feat(worker_new): use resetPassword funcionality
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Alex Moreno 2022-11-23 14:46:25 +01:00
parent cbdffc98a4
commit f70a9cb785
2 changed files with 6 additions and 79 deletions

View File

@ -227,7 +227,12 @@ module.exports = Self => {
throw e; throw e;
} }
await models.Worker.workerWelcomeEmail(client.id); await models.user.resetPassword({
email: args.email,
emailTemplate: 'worker-welcome',
id: client.id
});
return client.id; return client.id;
}; };
}; };

View File

@ -1,78 +0,0 @@
const {Email} = require('vn-print');
module.exports = Self => {
Self.remoteMethodCtx('workerWelcomeEmail', {
description:
'Sends the welcome email to the new worker',
accessType: 'WRITE',
accepts: [
{
arg: 'id',
type: 'number',
required: true,
description: 'The worker id',
http: {source: 'path'},
}
],
returns: {
type: ['object'],
root: true,
},
http: {
path: '/:id/worker-welcome-email',
verb: 'POST',
},
});
Self.workerWelcomeEmail = async ctx => {
const models = Self.app.models;
const userId = ctx.req.accessToken.userId;
const $t = ctx.req.__; // $translate
const origin = ctx.req.headers.origin;
const args = Object.assign({}, ctx.args);
const params = {
recipient: args.recipient,
lang: ctx.req.getLocale(),
};
delete args.ctx;
for (const param in args) params[param] = args[param];
const claim = await models.Claim.findById(args.id, {
fields: ['id', 'clientFk'],
include: {
relation: 'client',
scope: {
fields: ['name', 'salesPersonFk'],
},
},
});
const message = $t('Claim pickup order sent', {
claimId: args.id,
clientName: claim.client().name,
claimUrl: `${origin}/#!/claim/${args.id}/summary`,
});
const salesPersonId = claim.client().salesPersonFk;
if (salesPersonId)
await models.Chat.sendCheckingPresence(ctx, salesPersonId, message);
await models.ClaimLog.create({
originFk: args.id,
userFk: userId,
action: 'insert',
description: 'Claim-pickup-order sent',
changedModel: 'Mail',
});
const email = new Email('worker-welcome', {
recipient: args.email,
lang: ctx.req.getLocale(),
});
await email.send();
// TODO: or use same funcionality back/methods/account/recover-password.js
};
};