function login({ email, password }) {
    const self = this;
    return new Promise((resolve, reject) => {
        const isActive = true;
        self.findOne({ email, isActive }).exec()
            .then(admin => {
                if (admin) {
                    const hashedPassword = admin.password;
                    return PasswordServ.match(password, hashedPassword)
                        .then(isMatched => {
                            if (isMatched) {
                                const role = admin.role;
                                const adminId = admin.id;
                                return TokenServ.generate({ role, adminId });
                            } else {
                                const error = new Error(errors.login.password.wrong);
                                reject(error);
                            }
                        })
                } else {
                    const error = new Error(errors.login.email.wrong);
                    reject(error);
                }
            })
            .then(resolve)
            .catch(reject);
    })
}
// Upon Successfull Login Will Return Token (JWT)...
Upon Successfull Login Will Return Token (JWT)
Upon Successfull Login Will Return Token ( JWT )
function login({ email, password }) {
    const self = this;
    return new Promise((resolve, reject) => {
        const isActive = true;
        self.findOne({ email, isActive }).exec()
            .then(admin => {
                if (admin) {
                    const hashedPassword = admin.password;
                    return PasswordServ.match(password, hashedPassword)
                        .then(isMatched => {
                            if (isMatched) {
                                const role = admin.role;
                                const adminId = admin.id;
                                return TokenServ.generate({ role, adminId });
                            } else {
                                const error = new Error(errors.login.password.wrong);
                                reject(error);
                            }
                        })
                } else {
                    const error = new Error(errors.login.email.wrong);
                    reject(error);
                }
            })
            .then(resolve)
            .catch(reject);
    })
}
function login ( { email , password } ) { const self = this ; return new Promise ( ( resolve , reject ) => { const isActive = true ; self . findOne ( { email , isActive } ) . exec ( ) . then ( admin => { if ( admin ) { const hashedPassword = admin . password ; return PasswordServ . match ( password , hashedPassword ) . then ( isMatched => { if ( isMatched ) { const role = admin . role ; const adminId = admin . id ; return TokenServ . generate ( { role , adminId } ) ; } else { const error = new Error ( errors . login . password . wrong ) ; reject ( error ) ; } } ) } else { const error = new Error ( errors . login . email . wrong ) ; reject ( error ) ; } } ) . then ( resolve ) . catch ( reject ) ; } ) }
Upon Successfull Login Will Return Token (JWT)...
Upon Successfull Login Will Return Token ( JWT ) ...