diff --git a/back/models/notificationSubscription.js b/back/models/notificationSubscription.js index 674629413..f1b2811fa 100644 --- a/back/models/notificationSubscription.js +++ b/back/models/notificationSubscription.js @@ -47,22 +47,16 @@ module.exports = Self => { }; async function getUserToModify(notificationId, userFk, models) { - if (notificationId != null) { + let userToModify = userFk; + if (notificationId) { const subscription = await models.NotificationSubscription.findById(notificationId); - const user = await subscription.userFk; - return await models.Worker.findOne({ - fields: ['id', 'bossFk'], - where: { - id: user - } - }); - } else { - return await models.Worker.findOne({ - fields: ['id', 'bossFk'], - where: { - id: userFk - } - }); + userToModify = subscription.userFk; } + return await models.Worker.findOne({ + fields: ['id', 'bossFk'], + where: { + id: userToModify + } + }); } }; diff --git a/db/changes/230201/00-uniqueKeyNotificationSubscription.sql b/db/changes/230201/00-uniqueKeyNotificationSubscription.sql new file mode 100644 index 000000000..623ecf770 --- /dev/null +++ b/db/changes/230201/00-uniqueKeyNotificationSubscription.sql @@ -0,0 +1,4 @@ +ALTER TABLE + `util`.`notificationSubscription` +ADD + CONSTRAINT `notificationSubscription_UN` UNIQUE KEY (`notificationFk`, `userFk`); \ No newline at end of file