2023-05-10 11:22:53 +00:00
|
|
|
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;
|
2023-05-29 10:55:20 +00:00
|
|
|
|
2023-05-10 11:22:53 +00:00
|
|
|
const sector = await models.Sector.findById(instance.sectorFk, {
|
2023-05-29 10:55:20 +00:00
|
|
|
fields: ['mainPrinterFk']
|
2023-05-10 11:22:53 +00:00
|
|
|
}, options);
|
2023-05-29 10:55:20 +00:00
|
|
|
|
2023-05-10 11:22:53 +00:00
|
|
|
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(
|
|
|
|
{
|
2023-05-29 10:55:20 +00:00
|
|
|
'labelerId': instance.labelerFk,
|
|
|
|
'sectorId': instance.sectorFk,
|
|
|
|
'workerId': userId
|
2023-05-10 11:22:53 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
}, options);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|