feat: error handlers
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Vicent Llopis 2022-11-07 13:57:54 +01:00
parent ffa0ff650e
commit 7fc18c89df
3 changed files with 34 additions and 6 deletions

View File

@ -237,7 +237,9 @@
"Modifiable user details only by an administrator": "Detalles de usuario modificables solo por un administrador",
"Modifiable password only via recovery or by an administrator": "Contraseña modificable solo a través de la recuperación o por un administrador",
"Not enough privileges to edit a client": "No tienes suficientes privilegios para editar un cliente",
"Claim pickup order sent": "Reclamación Orden de recogida enviada [({{claimId}})]({{{claimUrl}}}) al cliente *{{clientName}}*",
"You don't have grant privilege": "No tienes privilegios para dar privilegios",
"You don't own the role and you can't assign it to another user": "No eres el propietario del rol y no puedes asignarlo a otro usuario"
}
"Claim pickup order sent": "Reclamación Orden de recogida enviada [({{claimId}})]({{{claimUrl}}}) al cliente *{{clientName}}*",
"You don't have grant privilege": "No tienes privilegios para dar privilegios",
"You don't own the role and you can't assign it to another user": "No eres el propietario del rol y no puedes asignarlo a otro usuario",
"Already has this status": "Ya tiene este estado",
"There aren't records for this week": "No existen registros para esta semana"
}

View File

@ -1,6 +1,6 @@
const models = require('vn-loopback/server/server').models;
fdescribe('workerTimeControl sendMail()', () => {
describe('workerTimeControl sendMail()', () => {
const workerId = 18;
const ctx = {
req: {

View File

@ -1,3 +1,4 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.remoteMethodCtx('updateWorkerTimeControlMail', {
description: 'Updates the state of WorkerTimeControlMail',
@ -39,6 +40,7 @@ module.exports = Self => {
Self.updateWorkerTimeControlMail = async(ctx, options) => {
const models = Self.app.models;
const args = ctx.args;
const userId = ctx.req.accessToken.userId;
const myOptions = {};
@ -53,9 +55,33 @@ module.exports = Self => {
}
}, myOptions);
return workerTimeControlMail.updateAttributes({
if (!workerTimeControlMail) throw new UserError(`There aren't records for this week`);
const oldState = workerTimeControlMail.state;
const oldEmailResponse = workerTimeControlMail.emailResponse;
if (oldState == args.state) throw new UserError('Already has this status');
await workerTimeControlMail.updateAttributes({
state: args.state,
emailResponse: args.emailResponse || null
}, myOptions);
const logRecord = {
originFk: args.workerId,
userFk: userId,
action: 'update',
changedModel: 'WorkerTimeControlMail',
oldInstance: {
state: oldState,
emailResponse: oldEmailResponse
},
newInstance: {
state: args.state,
emailResponse: args.emailResponse
}
};
return models.WorkerLog.create(logRecord, myOptions);
};
};