From 1682132e1c6b9020cc2be52f4c10ec2b08e9e284 Mon Sep 17 00:00:00 2001 From: Nathan Lamy Date: Tue, 24 Feb 2026 23:16:26 +0100 Subject: [PATCH] fix: notifications spam --- app/controllers/colles_controller.ts | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/app/controllers/colles_controller.ts b/app/controllers/colles_controller.ts index c80a51d..4afb255 100644 --- a/app/controllers/colles_controller.ts +++ b/app/controllers/colles_controller.ts @@ -187,9 +187,9 @@ export default class CollesController { parseFloat(beforeColle.grade) ) } - // if (!deepEqual(beforeColle, afterColle)) { - // await this.notificationService.sendNotification('COLLE_UPDATED', existing) - // } + if (hasChanged(beforeColle, afterColle)) { + await this.notificationService.sendNotification('COLLE_UPDATED', existing) + } return existing.save() } const colle = await Colle.create(colleData) @@ -269,9 +269,9 @@ export default class CollesController { const afterColle = oldColle.serialize() upcomingCollesIds.delete(oldColle.id) - if (beforeColle.room !== afterColle.room) { + if (beforeColle.roomId !== afterColle.roomId) { await this.notificationService.sendNotification('ROOM_UPDATED', oldColle) - } else if (!deepEqual(beforeColle, afterColle)) { + } else if (hasChanged(beforeColle, afterColle)) { await this.notificationService.sendNotification('COLLE_UPDATED', oldColle) } } @@ -298,6 +298,16 @@ export default class CollesController { } } -function deepEqual(a: any, b: any) { - return JSON.stringify(a) === JSON.stringify(b) -} +const propsToCheck = [ + 'examinerId', + 'bjsecret', + 'bjid', + 'grade', + 'content', + 'comment', + 'roomId', + 'date', + 'subjectId', +] +const hasChanged = (beforeColle: any, afterColle: any) => + propsToCheck.some((prop) => beforeColle[prop] !== afterColle[prop])