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

29 lines
994 B
JavaScript

module.exports = function(Self) {
Self.observe('after save', async function(ctx) {
const instance = ctx.instance;
const models = Self.app.models;
const options = ctx.options;
if (!instance.sectorFk || !instance.labelerFk) return;
const sector = await models.Sector.findById(instance.sectorFk, {
fields: ['mainPrinterFk']
}, options);
if (sector.mainPrinterFk && sector.mainPrinterFk != instance.labelerFk) {
const userId = ctx.options.accessToken.userId;
await models.NotificationQueue.create({
notificationFk: 'not-main-printer-configured',
authorFk: userId,
params: JSON.stringify(
{
'labelerId': instance.labelerFk,
'sectorId': instance.sectorFk,
'workerId': userId
}
)
}, options);
}
});
};