feat: auto generate placeholder nationalId for users and professors, auto calculate class end date

This commit is contained in:
2026-08-21 15:03:18 +03:30
parent cbcf3f55db
commit 30db6582b7
6 changed files with 157 additions and 21 deletions
+9
View File
@@ -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);