refs #5137 sql moved to template
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Alexandre Riera 2023-05-29 12:55:20 +02:00
parent ca9d76db77
commit 059467a383
8 changed files with 34 additions and 21 deletions

View File

@ -5,23 +5,21 @@ module.exports = function(Self) {
const options = ctx.options; const options = ctx.options;
if (!instance.sectorFk || !instance.labelerFk) return; if (!instance.sectorFk || !instance.labelerFk) return;
const sector = await models.Sector.findById(instance.sectorFk, { const sector = await models.Sector.findById(instance.sectorFk, {
fields: ['description', 'mainPrinterFk'] fields: ['mainPrinterFk']
}, options); }, options);
if (sector.mainPrinterFk && sector.mainPrinterFk != instance.labelerFk) { if (sector.mainPrinterFk && sector.mainPrinterFk != instance.labelerFk) {
const userId = ctx.options.accessToken.userId; const userId = ctx.options.accessToken.userId;
const user = await models.VnUser.findById(userId, {fields: ['nickname']}, options);
const labeler = await models.Printer.findById(instance.labelerFk, {fields: ['name']}, options);
const mainPrinter = await models.Printer.findById(sector.mainPrinterFk, {fields: ['name']}, options);
await models.NotificationQueue.create({ await models.NotificationQueue.create({
notificationFk: 'not-main-printer-configured', notificationFk: 'not-main-printer-configured',
authorFk: userId, authorFk: userId,
params: JSON.stringify( params: JSON.stringify(
{ {
'labeler': `#${instance.labelerFk} ${labeler.name}`, 'labelerId': instance.labelerFk,
'sector': `#${instance.sectorFk} ${sector.description}`, 'sectorId': instance.sectorFk,
'mainPrinter': `#${sector.mainPrinterFk} ${mainPrinter.name}`, 'workerId': userId
'worker': `#${userId} ${user.nickname}`
} }
) )
}, options); }, options);

View File

@ -1,3 +1,3 @@
subject: Not main printer configured subject: Not main printer configured
title: Not main printer configured title: Not main printer configured
description: Printer {0} has been configured in sector {1} (the main printer for that sector is {2}). Ask the worker {3} description: 'Printer #{0} {1} has been configured in sector #{2} {3} (the main printer for that sector is #{4} {5}). Ask the worker {6}.'

View File

@ -1,3 +1,3 @@
subject: Configurada impresora no principal subject: Configurada impresora no principal
title: Configurada impresora no principal title: Configurada impresora no principal
description: Se ha configurado la impresora {0} en el sector {1} (la impresora principal de ese sector es la {2}). Preguntar al trabajador {3}. description: 'Se ha configurado la impresora #{0} {1} en el sector #{2} {3} (la impresora principal de ese sector es la #{4} {5}). Preguntar al trabajador {6}.'

View File

@ -2,7 +2,7 @@
<div class="grid-row"> <div class="grid-row">
<div class="grid-block vn-pa-ml"> <div class="grid-block vn-pa-ml">
<h1>{{ $t('title') }}</h1> <h1>{{ $t('title') }}</h1>
<p v-html="$t('description', [labeler, sector, mainPrinter, worker])"></p> <p v-html="$t('description', [labeler.id, labeler.name, sector.id, sector.description, mainPrinter.id, mainPrinter.name, worker.nickname])"></p>
</div> </div>
</div> </div>
</email-body> </email-body>

View File

@ -3,24 +3,30 @@ const emailBody = new Component('email-body');
module.exports = { module.exports = {
name: 'not-main-printer-configured', name: 'not-main-printer-configured',
async serverPrefetch() {
this.sector = await this.findOneFromDef('sector', [this.sectorId]);
if (!this.sector)
throw new Error('Something went wrong');
this.labeler = await this.findOneFromDef('printer', [this.labelerId]);
this.mainPrinter = await this.findOneFromDef('printer', [this.sector.mainPrinterFk]);
this.worker = await this.findOneFromDef('worker', [this.workerId]);
},
components: { components: {
'email-body': emailBody.build(), 'email-body': emailBody.build(),
}, },
props: { props: {
labeler: { labelerId: {
type: String, type: Number,
required: true required: true
}, },
sector: { sectorId: {
type: String, type: Number,
required: true required: true
}, },
mainPrinter: { workerId: {
type: String, type: Number,
required: true
},
worker: {
type: String,
required: true required: true
} }
} }

View File

@ -0,0 +1,3 @@
SELECT id, name
FROM vn.printer
WHERE id = ?

View File

@ -0,0 +1,3 @@
SELECT id, description, mainPrinterFk
FROM vn.sector
WHERE id = ?

View File

@ -0,0 +1,3 @@
SELECT nickname
FROM account.user
WHERE id = ?