mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
@@ -45,7 +45,7 @@ const { generateOTP, getOTPExpiry, isOTPExpired } = require('../utils/otp.util')
|
||||
const { onUserRegistered } = require('../services/achievements.service');
|
||||
const AdminNotification = require('../models/notifications/admin_notification.mdl');
|
||||
const UserNotification = require('../models/notifications/user_notification.mdl');
|
||||
const { renderNotification } = require('../services/notificationTemplate.service');
|
||||
const { NOTIFICATION_REGISTRY } = require('../data/notifications.data');
|
||||
const { sendEmail } = require('../services/email.service');
|
||||
const buildSessionInfo = require('../utils/session_info.util');
|
||||
const logActivity = require('../utils/logActivity.util');
|
||||
@@ -171,19 +171,17 @@ exports.register = async (req, res) => {
|
||||
|
||||
// Fire-and-forget: notify admins — explicit group or NOGRP fallback
|
||||
if (group) {
|
||||
renderNotification({ type: 'user_registration', data: {
|
||||
AdminNotification.create(NOTIFICATION_REGISTRY.user_registration.build({
|
||||
groupName: group.name,
|
||||
groupCode: group.group_code,
|
||||
userEmail: email,
|
||||
} })
|
||||
.then(notify => AdminNotification.create(notify))
|
||||
}))
|
||||
.catch(err => console.error('[AUTH] Failed to emit user_registration notification:', err));
|
||||
} else if (enrollGroup) {
|
||||
renderNotification({ type: 'nogrp_user_registered', data: {
|
||||
AdminNotification.create(NOTIFICATION_REGISTRY.nogrp_user_registered.build({
|
||||
userEmail: email,
|
||||
regType: 'system',
|
||||
} })
|
||||
.then(notify => AdminNotification.create(notify))
|
||||
}))
|
||||
.catch(err => console.error('[AUTH] Failed to emit nogrp_user_registered notification:', err));
|
||||
}
|
||||
|
||||
@@ -241,12 +239,12 @@ exports.verifyOTP = async (req, res) => {
|
||||
const notifications = [
|
||||
{
|
||||
user_id: user.user_id,
|
||||
...(await renderNotification({ type: 'welcome', data: {
|
||||
...NOTIFICATION_REGISTRY.welcome.build({
|
||||
groupName: grp?.name ?? null,
|
||||
groupCode: grp?.group_code ?? null,
|
||||
accType: user.acc_type,
|
||||
groupId: membership?.group_id ?? null,
|
||||
} })),
|
||||
}),
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
},
|
||||
@@ -254,7 +252,7 @@ exports.verifyOTP = async (req, res) => {
|
||||
if (grp?.group_code === 'NOGRP') {
|
||||
notifications.push({
|
||||
user_id: user.user_id,
|
||||
...(await renderNotification({ type: 'nogrp_welcome', data: {} })),
|
||||
...NOTIFICATION_REGISTRY.nogrp_welcome.build(),
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
});
|
||||
@@ -475,11 +473,10 @@ exports.googleCallback = async (req, res) => {
|
||||
// Welcome email/achievements/welcome-notification are deferred to
|
||||
// verifyOTP's first-time branch now (this account isn't verified yet —
|
||||
// it still has to complete the same OTP gate as a system registration).
|
||||
renderNotification({ type: 'nogrp_user_registered', data: {
|
||||
AdminNotification.create(NOTIFICATION_REGISTRY.nogrp_user_registered.build({
|
||||
userEmail: payload.email,
|
||||
regType: 'google',
|
||||
} })
|
||||
.then(notify => AdminNotification.create(notify))
|
||||
}))
|
||||
.catch(err => console.error('[AUTH] googleCallback: Failed to emit nogrp_user_registered notification:', err));
|
||||
} catch (err) {
|
||||
await t.rollback();
|
||||
|
||||
Reference in New Issue
Block a user