perform test

test to courses

Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
2026-06-24 12:48:51 +08:00
parent 358fecb510
commit 9b8577b79b
27 changed files with 1122 additions and 221 deletions
+49 -22
View File
@@ -70,11 +70,15 @@ exports.register = async (req, res) => {
});
if (!group) return R.error(res, 'Invalid or inactive group code.', 400);
}
// ── Resolve enroll target (explicit group or NOGRP fallback) ──────────────
const enrollGroup = group
?? await mdl_UserGroups.findOne({ where: { group_code: 'NOGRP', is_active: true } });
// ── Create user ───────────────────────────────────────────────────────────
const hashed = await bcrypt.hash(password, 12);
const otp = generateOTP();
const user = await mdl_Users.create({
email,
password: hashed,
@@ -85,23 +89,24 @@ exports.register = async (req, res) => {
reg_type: 'system',
acc_type: 'user',
personal_info: personal_info ?? null,
needs_intro: true,
createdBy: null,
}, { transaction });
// ── Enroll into group ─────────────────────────────────────────────────────
if (group) {
if (enrollGroup) {
await mdl_UserGroupMembers.create({
group_id: group.group_id,
group_id: enrollGroup.group_id,
user_id: user.user_id,
createdBy: null,
}, { transaction });
}
await sendEmail({ to: email, type: 'OTP', data: { otp } });
await transaction.commit();
// Fire-and-forget: notify admins about the new group registration
// Fire-and-forget: notify admins only for explicit group code registrations
if (group) {
AdminNotification.create({
...NOTIFICATION_REGISTRY.user_registration.build({
@@ -318,21 +323,43 @@ exports.googleCallback = async (req, res) => {
// Find or auto-create the user.
let user = await mdl_Users.findOne({ where: { email: payload.email } });
if (!user) {
user = await mdl_Users.create({
email: payload.email,
reg_type: 'google',
acc_type: 'user',
is_active: true,
is_verified: true,
personal_info: {
name: {
given_name: payload.given_name ?? '',
last_name: payload.family_name ?? '',
full_name: payload.name ?? '',
const t = await sequelize.transaction();
try {
user = await mdl_Users.create({
email: payload.email,
reg_type: 'google',
acc_type: 'user',
is_active: true,
is_verified: true,
needs_intro: true,
personal_info: {
name: {
given_name: payload.given_name ?? '',
last_name: payload.family_name ?? '',
full_name: payload.name ?? '',
},
avatar: { url: payload.picture ?? null },
},
avatar: { url: payload.picture ?? null },
},
});
}, { transaction: t });
const noGrp = await mdl_UserGroups.findOne({ where: { group_code: 'NOGRP', is_active: true }, transaction: t });
if (noGrp) {
await mdl_UserGroupMembers.create({
group_id: noGrp.group_id,
user_id: user.user_id,
createdBy: null,
}, { transaction: t });
}
await t.commit();
// Fire-and-forget: achievements + welcome notification for new Google user
onUserRegistered(user.user_id)
.catch(err => console.error('[AUTH] googleCallback: Failed to grant achievements:', err));
} catch (err) {
await t.rollback();
throw err;
}
}
if (!user.is_active) {