function createNew({ email, password, fullName }) {
    const self = this;
    return new Promise((resolve, reject) => {
        const isActive = true;
        self.findOne({ email, isActive }).exec()
            .then(admin => {
                if (admin) {
                    // If Admin With Given Email ID Already Exist Throw Error;
                    const error = new Error('Admin With Given User Id Already Exist');
                    reject(error);
                } else {
                    return PasswordServ.hash(password);
                }
            })
            .then(hashedPassword => {
                const password = hashedPassword;
                const admin = new Admin({ email, password, fullName });
                return admin.save()
            })
            .then(resolve)
            .catch(reject)
    });
}
// If Not Exist This Will Create New One
If Not Exist This Will Create New One
If Not Exist This Will Create New One
function createNew({ email, password, fullName }) {
    const self = this;
    return new Promise((resolve, reject) => {
        const isActive = true;
        self.findOne({ email, isActive }).exec()
            .then(admin => {
                if (admin) {
                    const error = new Error('Admin With Given User Id Already Exist');
                    reject(error);
                } else {
                    return PasswordServ.hash(password);
                }
            })
            .then(hashedPassword => {
                const password = hashedPassword;
                const admin = new Admin({ email, password, fullName });
                return admin.save()
            })
            .then(resolve)
            .catch(reject)
    });
}
function createNew ( { email , password , fullName } ) { const self = this ; return new Promise ( ( resolve , reject ) => { const isActive = true ; self . findOne ( { email , isActive } ) . exec ( ) . then ( admin => { if ( admin ) { const error = new Error ( 'Admin With Given User Id Already Exist' ) ; reject ( error ) ; } else { return PasswordServ . hash ( password ) ; } } ) . then ( hashedPassword => { const password = hashedPassword ; const admin = new Admin ( { email , password , fullName } ) ; return admin . save ( ) } ) . then ( resolve ) . catch ( reject ) } ) ; }
If Not Exist This Will Create New One
If Not Exist This Will Create New One
// If Admin With Given Email ID Already Exist Throw Error;