feat: auto generate placeholder nationalId for users and professors, auto calculate class end date
This commit is contained in:
@@ -17,6 +17,7 @@ const {
|
||||
assertCanResetPasswordAndSms,
|
||||
isCredentialsSmsDelivered
|
||||
} = require('./passwordReset');
|
||||
const { allocatePlaceholderNationalId } = require('../../utils/nationalId');
|
||||
|
||||
const normalizeAdminNotes = (value) => {
|
||||
if (value == null) return undefined;
|
||||
@@ -106,6 +107,10 @@ const signUp = async (body) => {
|
||||
const userRole = await Role.findOne({ name: 'User' });
|
||||
if (!userRole) throw new AppError('DEFAULT_ROLE_NOT_FOUND');
|
||||
|
||||
if (!profile.nationalIdCode) {
|
||||
profile.nationalIdCode = await allocatePlaceholderNationalId(profile.phoneNumber);
|
||||
}
|
||||
|
||||
const passwordHash = await bcrypt.hash(password, 10);
|
||||
const user = await User.create({
|
||||
...profile,
|
||||
@@ -171,6 +176,10 @@ const createUserAdmin = async (body) => {
|
||||
}
|
||||
if (!roleObj) throw new AppError('DEFAULT_ROLE_NOT_FOUND');
|
||||
|
||||
if (!profile.nationalIdCode) {
|
||||
profile.nationalIdCode = await allocatePlaceholderNationalId(profile.phoneNumber);
|
||||
}
|
||||
|
||||
const plainPassword = (requestedPassword && String(requestedPassword).trim()) || generateSimplePassword();
|
||||
const username = await allocateUniqueUsername(requestedUsername);
|
||||
const passwordHash = await bcrypt.hash(plainPassword, 10);
|
||||
|
||||
Reference in New Issue
Block a user