add: more commits

Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
2026-07-03 21:40:24 +08:00
parent 1d12f04967
commit a572c1e25f
17 changed files with 476 additions and 302 deletions
+4 -5
View File
@@ -35,7 +35,7 @@ const { onCourseCompleted } = require('../../services/achievements.service'
const PendingCertificate = require('../../models/courses/pending_certificate.mdl');
const Certificate = require('../../models/courses/certificate.mdl');
const UserNotification = require('../../models/notifications/user_notification.mdl');
const { NOTIFICATION_REGISTRY } = require('../../data/notifications.data');
const { renderNotification } = require('../../services/notificationTemplate.service');
const notDeleted = { deletedAt: null };
@@ -956,10 +956,9 @@ exports.submitCourseAssessment = async (req, res) => {
}
// Immediate notification: course completed, certificate incoming
UserNotification.create({
user_id,
...NOTIFICATION_REGISTRY.course_completed.build({ courseTitle: course?.title ?? '', courseUuid: course?.uuid ?? null }),
}).catch(err => console.error('[ASSESSMENT] Failed to emit course_completed notification:', err));
renderNotification({ type: 'course_completed', data: { courseTitle: course?.title ?? '', courseUuid: course?.uuid ?? null } })
.then(notify => UserNotification.create({ user_id, ...notify }))
.catch(err => console.error('[ASSESSMENT] Failed to emit course_completed notification:', err));
}
return R.success(res, "Assessment submitted.", {
+8 -9
View File
@@ -22,7 +22,7 @@ const { onTierActivated } = require('../../services/achievements.service');
const { Course } = require('../../models/courses/courses.mdl');
const paymentSvc = require('../../services/payment.service');
const R = require('../../utils/response.util');
const { NOTIFICATION_REGISTRY } = require('../../data/notifications.data');
const { renderNotification } = require('../../services/notificationTemplate.service');
require('../../models/tiers/tier.associations');
@@ -49,14 +49,13 @@ exports.getMyTier = async (req, res) => {
// ── Inline safety net: expire between cron ticks ──────────────────────────
if (tier && tier.expires_at && new Date(tier.expires_at) <= new Date()) {
await tier.update({ status: 'expired' });
UserNotification.create({
user_id: req.user.user_id,
...NOTIFICATION_REGISTRY.tier_expired.build({
tier: tier.tier,
label: tier.plan?.label ?? null,
planId: tier.plan?.plan_id ?? null,
}),
}).catch(() => {});
renderNotification({ type: 'tier_expired', data: {
tier: tier.tier,
label: tier.plan?.label ?? null,
planId: tier.plan?.plan_id ?? null,
} })
.then(notify => UserNotification.create({ user_id: req.user.user_id, ...notify }))
.catch(() => {});
return R.success(res, 'Active tier retrieved.', {
tier: 'free', status: 'active', category: null, just_expired: true,
});