feat: refs #7343 delete sending to user #3334
|
@ -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
|
||||
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');
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
De la linea 34 a la 40 crec que pots unificar-ho
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.
Has probado esto?
Dona error 400 amb el codi que m'has passat:
Pero te has asegurat de que realment tinga email en la db?