feat: refs #7343 delete sending to user #3334

Merged
ivanm merged 3 commits from 7343-modifyDriverRouteEmail into dev 2025-01-08 12:17:50 +00:00
1 changed files with 4 additions and 17 deletions
Showing only changes of commit 8822fde7fb - Show all commits

View File

@ -8,7 +8,7 @@ module.exports = Self => {
arg: 'id',
type: 'number',
required: true,
description: 'The client id',
description: 'The route id',
http: {source: 'path'}
}, {
arg: 'replyTo',
@ -31,26 +31,13 @@ module.exports = Self => {
});
Self.driverRouteEmail = async(ctx, id) => {
const models = Self.app.models;
const {workerFk, agencyMode} = await Self.findById(id, {
fields: ['workerFk', 'agencyModeFk'],
const {agencyMode} = await Self.findById(id, {
ivanm marked this conversation as resolved
Review

De la linea 34 a la 40 crec que pots unificar-ho

De la linea 34 a la 40 crec que pots unificar-ho
Review

He intentat unificar-ho de varies formes, he intentat fer un scope de reportMail per a que només carregue eixa columna, però no he trobat la forma. He anat a la api varies vegades i sempre m'ha donat error. Amb el codi com el tens la api respon correctament. Si tens alguna idea per a unificar més eixes linies m'ho dius i faig la prova.

He intentat unificar-ho de varies formes, he intentat fer un scope de reportMail per a que només carregue eixa columna, però no he trobat la forma. He anat a la api varies vegades i sempre m'ha donat error. Amb el codi com el tens la api respon correctament. Si tens alguna idea per a unificar més eixes linies m'ho dius i faig la prova.
Review

Has probado esto?

const route = await Self.findById(id, {
    fields: ['agencyModeFk'],
    include: {relation: 'agencyMode'}
});

ctx.args.recipient = route?.agencyMode?.reportMail;
Has probado esto? ``` const route = await Self.findById(id, { fields: ['agencyModeFk'], include: {relation: 'agencyMode'} }); ctx.args.recipient = route?.agencyMode?.reportMail; ```
Review

Dona error 400 amb el codi que m'has passat:

{
  "error": {
    "statusCode": 400,
    "name": "UserError",
    "message": "Es necesario un email",
    "translateArgs": [],
    "stack": "UserError: Es necesario un email\n    at Self.driverRouteEmail (/home/ivanm/Projects/salix/modules/route/back/methods/route/driverRouteEmail.js:40:40)"
  }
}
Dona error 400 amb el codi que m'has passat: ``` { "error": { "statusCode": 400, "name": "UserError", "message": "Es necesario un email", "translateArgs": [], "stack": "UserError: Es necesario un email\n at Self.driverRouteEmail (/home/ivanm/Projects/salix/modules/route/back/methods/route/driverRouteEmail.js:40:40)" } } ```
Review

Pero te has asegurat de que realment tinga email en la db?

Pero te has asegurat de que realment tinga email en la db?
fields: ['agencyModeFk'],
include: {relation: 'agencyMode'}
});
const {reportMail} = agencyMode();
let user;
let account;
if (workerFk) {
user = await models.VnUser.findById(workerFk, {
fields: ['active', 'id'],
include: {relation: 'emailUser'}
});
account = await models.Account.findById(workerFk);
}
if (user?.active && account) ctx.args.recipient = user.emailUser().email;
else ctx.args.recipient = reportMail;
ctx.args.recipient = reportMail;
if (!ctx.args.recipient) throw new UserError('An email is necessary');
return Self.sendTemplate(ctx, 'driver-route');
};