mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
add: more commits
Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
@@ -36,7 +36,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 { NOTIFICATION_REGISTRY } = require('../data/notifications.data');
|
||||
const { renderNotification } = require('../services/notificationTemplate.service');
|
||||
const { sendEmail } = require('../services/email.service');
|
||||
const buildSessionInfo = require('../utils/session_info.util');
|
||||
const logActivity = require('../utils/logActivity.util');
|
||||
@@ -109,20 +109,20 @@ exports.register = async (req, res) => {
|
||||
|
||||
// Fire-and-forget: notify admins — explicit group or NOGRP fallback
|
||||
if (group) {
|
||||
AdminNotification.create({
|
||||
...NOTIFICATION_REGISTRY.user_registration.build({
|
||||
groupName: group.name,
|
||||
groupCode: group.group_code,
|
||||
userEmail: email,
|
||||
}),
|
||||
}).catch(err => console.error('[AUTH] Failed to emit user_registration notification:', err));
|
||||
renderNotification({ type: 'user_registration', data: {
|
||||
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) {
|
||||
AdminNotification.create({
|
||||
...NOTIFICATION_REGISTRY.nogrp_user_registered.build({
|
||||
userEmail: email,
|
||||
regType: 'system',
|
||||
}),
|
||||
}).catch(err => console.error('[AUTH] Failed to emit nogrp_user_registered notification:', err));
|
||||
renderNotification({ type: 'nogrp_user_registered', data: {
|
||||
userEmail: email,
|
||||
regType: 'system',
|
||||
} })
|
||||
.then(notify => AdminNotification.create(notify))
|
||||
.catch(err => console.error('[AUTH] Failed to emit nogrp_user_registered notification:', err));
|
||||
}
|
||||
|
||||
return R.success(res, 'Registration successful. Please check your email for the OTP.', {
|
||||
@@ -182,12 +182,12 @@ exports.verifyOTP = async (req, res) => {
|
||||
const notifications = [
|
||||
{
|
||||
user_id: user.user_id,
|
||||
...NOTIFICATION_REGISTRY.welcome.build({
|
||||
...(await renderNotification({ type: 'welcome', data: {
|
||||
groupName: grp?.name ?? null,
|
||||
groupCode: grp?.group_code ?? null,
|
||||
accType: user.acc_type,
|
||||
groupId: membership?.group_id ?? null,
|
||||
}),
|
||||
} })),
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
},
|
||||
@@ -195,7 +195,7 @@ exports.verifyOTP = async (req, res) => {
|
||||
if (grp?.group_code === 'NOGRP') {
|
||||
notifications.push({
|
||||
user_id: user.user_id,
|
||||
...NOTIFICATION_REGISTRY.nogrp_welcome.build(),
|
||||
...(await renderNotification({ type: 'nogrp_welcome', data: {} })),
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
});
|
||||
@@ -405,28 +405,21 @@ exports.googleCallback = async (req, res) => {
|
||||
.catch(err => console.error('[AUTH] googleCallback: Failed to grant achievements:', err));
|
||||
|
||||
const _now = new Date();
|
||||
UserNotification.bulkCreate([
|
||||
{
|
||||
user_id: user.user_id,
|
||||
...NOTIFICATION_REGISTRY.welcome.build({ groupName: null, groupCode: 'NOGRP', accType: 'user', groupId: noGrp?.group_id ?? null }),
|
||||
createdAt: _now,
|
||||
updatedAt: _now,
|
||||
},
|
||||
{
|
||||
user_id: user.user_id,
|
||||
...NOTIFICATION_REGISTRY.nogrp_welcome.build(),
|
||||
createdAt: _now,
|
||||
updatedAt: _now,
|
||||
},
|
||||
], { validate: false })
|
||||
Promise.all([
|
||||
renderNotification({ type: 'welcome', data: { groupName: null, groupCode: 'NOGRP', accType: 'user', groupId: noGrp?.group_id ?? null } }),
|
||||
renderNotification({ type: 'nogrp_welcome', data: {} }),
|
||||
]).then(([welcomeNotify, nogrpNotify]) => UserNotification.bulkCreate([
|
||||
{ user_id: user.user_id, ...welcomeNotify, createdAt: _now, updatedAt: _now },
|
||||
{ user_id: user.user_id, ...nogrpNotify, createdAt: _now, updatedAt: _now },
|
||||
], { validate: false }))
|
||||
.catch(err => console.error('[AUTH] googleCallback: Failed to emit welcome notifications:', err));
|
||||
|
||||
AdminNotification.create({
|
||||
...NOTIFICATION_REGISTRY.nogrp_user_registered.build({
|
||||
userEmail: payload.email,
|
||||
regType: 'google',
|
||||
}),
|
||||
}).catch(err => console.error('[AUTH] googleCallback: Failed to emit nogrp_user_registered notification:', err));
|
||||
renderNotification({ type: 'nogrp_user_registered', data: {
|
||||
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();
|
||||
throw err;
|
||||
|
||||
Reference in New Issue
Block a user