salix/modules/worker/back/models/operator.js

30 lines
1.0 KiB
JavaScript
Raw Normal View History

2023-11-02 15:25:25 +00:00
module.exports = Self => {
Self.observe('after save', async ctx => {
2023-06-22 06:56:27 +00:00
const instance = ctx.data || ctx.instance;
const models = Self.app.models;
const options = ctx.options;
const notification = 'backup-printer-selected';
const {userId} = ctx.options.accessToken;
2023-06-22 06:56:27 +00:00
if (!instance?.sectorFk || !instance?.labelerFk) return;
2023-05-29 10:55:20 +00:00
const sector = await models.Sector.findById(instance.sectorFk, {
fields: ['backupPrinterFk']
}, options);
2023-05-29 10:55:20 +00:00
if (sector.backupPrinterFk && sector.backupPrinterFk == instance.labelerFk) {
await models.NotificationQueue.create({
notificationFk: notification,
authorFk: userId,
params: JSON.stringify(
{
'labelerId': instance.labelerFk,
'sectorId': instance.sectorFk,
'workerId': userId
}
)
}, options);
}
});
};