diff --git a/modules/worker/back/methods/worker/new.js b/modules/worker/back/methods/worker/new.js index a57ca8c21..7a61434f0 100644 --- a/modules/worker/back/methods/worker/new.js +++ b/modules/worker/back/methods/worker/new.js @@ -227,7 +227,12 @@ module.exports = Self => { throw e; } - await models.Worker.workerWelcomeEmail(client.id); + await models.user.resetPassword({ + email: args.email, + emailTemplate: 'worker-welcome', + id: client.id + }); + return client.id; }; }; diff --git a/modules/worker/back/methods/worker/workerWelcomeEmail.js b/modules/worker/back/methods/worker/workerWelcomeEmail.js deleted file mode 100644 index 7462df34d..000000000 --- a/modules/worker/back/methods/worker/workerWelcomeEmail.js +++ /dev/null @@ -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 - }; -};