fix: notifications spam

This commit is contained in:
Nathan Lamy 2026-02-24 23:16:26 +01:00
parent 02ce8bd5b4
commit 1682132e1c

View file

@ -187,9 +187,9 @@ export default class CollesController {
parseFloat(beforeColle.grade) parseFloat(beforeColle.grade)
) )
} }
// if (!deepEqual(beforeColle, afterColle)) { if (hasChanged(beforeColle, afterColle)) {
// await this.notificationService.sendNotification('COLLE_UPDATED', existing) await this.notificationService.sendNotification('COLLE_UPDATED', existing)
// } }
return existing.save() return existing.save()
} }
const colle = await Colle.create(colleData) const colle = await Colle.create(colleData)
@ -269,9 +269,9 @@ export default class CollesController {
const afterColle = oldColle.serialize() const afterColle = oldColle.serialize()
upcomingCollesIds.delete(oldColle.id) upcomingCollesIds.delete(oldColle.id)
if (beforeColle.room !== afterColle.room) { if (beforeColle.roomId !== afterColle.roomId) {
await this.notificationService.sendNotification('ROOM_UPDATED', oldColle) await this.notificationService.sendNotification('ROOM_UPDATED', oldColle)
} else if (!deepEqual(beforeColle, afterColle)) { } else if (hasChanged(beforeColle, afterColle)) {
await this.notificationService.sendNotification('COLLE_UPDATED', oldColle) await this.notificationService.sendNotification('COLLE_UPDATED', oldColle)
} }
} }
@ -298,6 +298,16 @@ export default class CollesController {
} }
} }
function deepEqual(a: any, b: any) { const propsToCheck = [
return JSON.stringify(a) === JSON.stringify(b) 'examinerId',
} 'bjsecret',
'bjid',
'grade',
'content',
'comment',
'roomId',
'date',
'subjectId',
]
const hasChanged = (beforeColle: any, afterColle: any) =>
propsToCheck.some((prop) => beforeColle[prop] !== afterColle[prop])