4658-createWorker #1236
|
@ -1,5 +1,4 @@
|
|||
const md5 = require('md5');
|
||||
const {Email} = require('vn-print');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('new', {
|
||||
|
@ -10,113 +9,113 @@ module.exports = Self => {
|
|||
arg: 'fi',
|
||||
type: 'string',
|
||||
description: `The fi of worker`,
|
||||
required: true
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'name',
|
||||
type: 'string',
|
||||
description: `REPLACE!`,
|
||||
required: true
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'firstName',
|
||||
type: 'string',
|
||||
description: `REPLACE!`,
|
||||
required: true
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'lastNames',
|
||||
type: 'string',
|
||||
description: `REPLACE!`,
|
||||
required: true
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'email',
|
||||
type: 'string',
|
||||
description: `REPLACE!`,
|
||||
required: true
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'roleFk',
|
||||
type: 'number',
|
||||
description: `REPLACE!`,
|
||||
required: true
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'street',
|
||||
type: 'string',
|
||||
description: `REPLACE!`,
|
||||
required: true
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'city',
|
||||
type: 'string',
|
||||
description: `REPLACE!`,
|
||||
required: true
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'provinceFk',
|
||||
type: 'number',
|
||||
description: `REPLACE!`,
|
||||
required: true
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'iban',
|
||||
type: 'string',
|
||||
description: `REPLACE!`,
|
||||
required: true
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'bankEntityFk',
|
||||
type: 'number',
|
||||
description: `REPLACE!`,
|
||||
required: true
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'companyFk',
|
||||
type: 'number',
|
||||
description: `REPLACE!`,
|
||||
required: true
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'postcode',
|
||||
type: 'string',
|
||||
description: `REPLACE!`,
|
||||
required: true
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'phone',
|
||||
type: 'string',
|
||||
description: `REPLACE!`,
|
||||
required: true
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'code',
|
||||
type: 'string',
|
||||
description: `REPLACE!`,
|
||||
required: true
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'bossFk',
|
||||
type: 'number',
|
||||
description: `REPLACE!`,
|
||||
required: true
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'birth',
|
||||
type: 'date',
|
||||
description: `REPLACE!`,
|
||||
required: true
|
||||
}
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
returns: {
|
||||
alexm marked this conversation as resolved
Outdated
|
||||
type: 'number',
|
||||
root: true
|
||||
root: true,
|
||||
},
|
||||
http: {
|
||||
path: `/new`,
|
||||
verb: 'POST'
|
||||
}
|
||||
verb: 'POST',
|
||||
},
|
||||
});
|
||||
|
||||
Self.new = async(ctx, options) => {
|
||||
|
@ -126,8 +125,7 @@ module.exports = Self => {
|
|||
|
||||
let tx;
|
||||
console.log(args);
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
if (typeof options == 'object') Object.assign(myOptions, options);
|
||||
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
|
@ -136,26 +134,38 @@ module.exports = Self => {
|
|||
|
||||
let client;
|
||||
try {
|
||||
client = await models.Client.findOne({
|
||||
client = await models.Client.findOne(
|
||||
{
|
||||
where: {fi: args.fi},
|
||||
}, myOptions);
|
||||
},
|
||||
myOptions
|
||||
);
|
||||
|
||||
if (!client) {
|
||||
const nickname = args.firstName.concat(' ', args.lastNames);
|
||||
const randomPassword = await models.Worker.rawSql('SELECT account.passwordGenerate();');
|
||||
const user = await models.Account.create({
|
||||
const randomPassword = await models.Worker.rawSql(
|
||||
'SELECT account.passwordGenerate();'
|
||||
);
|
||||
const user = await models.Account.create(
|
||||
{
|
||||
name: args.name,
|
||||
nickname,
|
||||
password: md5(randomPassword),
|
||||
email: args.email,
|
||||
role: args.role
|
||||
}, myOptions);
|
||||
role: args.role,
|
||||
},
|
||||
myOptions
|
||||
);
|
||||
|
||||
await models.UserAccount.create({
|
||||
id: user.id
|
||||
}, myOptions);
|
||||
await models.UserAccount.create(
|
||||
{
|
||||
id: user.id,
|
||||
},
|
||||
alexm marked this conversation as resolved
Outdated
jgallego
commented
preguntar a laboral si lo quitamos de la creacion. preguntar a laboral si lo quitamos de la creacion.
Preguntar si al crearlo alguna vez ponen algo distinto a employee
alexm
commented
Quitar Quitar
|
||||
myOptions
|
||||
);
|
||||
|
||||
await models.Worker.rawSql('CALL vn.clientCreate(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
|
||||
await models.Worker.rawSql(
|
||||
'CALL vn.clientCreate(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
|
||||
[
|
||||
args.firstName,
|
||||
args.lastNames,
|
||||
|
@ -167,11 +177,13 @@ module.exports = Self => {
|
|||
args.companyFk,
|
||||
args.phone,
|
||||
args.email,
|
||||
user.id
|
||||
]
|
||||
, myOptions);
|
||||
user.id,
|
||||
],
|
||||
myOptions
|
||||
);
|
||||
|
||||
const address = await models.Address.create({
|
||||
const address = await models.Address.create(
|
||||
{
|
||||
clientFk: user.id,
|
||||
street: args.street,
|
||||
city: args.city,
|
||||
|
@ -179,19 +191,24 @@ module.exports = Self => {
|
|||
postalCode: args.postalCode,
|
||||
mobile: args.phone,
|
||||
nickname: 'TR ' + nickname,
|
||||
isDefaultAddress: true
|
||||
}, myOptions);
|
||||
isDefaultAddress: true,
|
||||
},
|
||||
myOptions
|
||||
);
|
||||
|
||||
client = await models.Client.findById(user.id, null, myOptions);
|
||||
|
||||
console.log(address.id);
|
||||
await client.updateAttributes({
|
||||
await client.updateAttributes(
|
||||
alexm marked this conversation as resolved
Outdated
jgallego
commented
Preguntar a Alicia si esto aun es útil Preguntar a Alicia si esto aun es útil
|
||||
{
|
||||
iban: args.iban,
|
||||
bankEntityFk: args.bankEntityFk,
|
||||
defaultAddressFk: address.id
|
||||
}, myOptions);
|
||||
defaultAddressFk: address.id,
|
||||
},
|
||||
myOptions
|
||||
alexm marked this conversation as resolved
Outdated
jgallego
commented
preguntar si en estos casos sí es posible el null preguntar si en estos casos sí es posible el null
|
||||
);
|
||||
}
|
||||
await models.Worker.rawSql('CALL vn.workerCreate(?, ?, ?, ?, ?, ?, ?)',
|
||||
await models.Worker.rawSql(
|
||||
'CALL vn.workerCreate(?, ?, ?, ?, ?, ?, ?)',
|
||||
[
|
||||
args.firstName,
|
||||
args.lastNames,
|
||||
|
@ -199,9 +216,10 @@ module.exports = Self => {
|
|||
args.bossFk,
|
||||
client.id,
|
||||
args.fi,
|
||||
args.birth
|
||||
]
|
||||
, myOptions);
|
||||
args.birth,
|
||||
],
|
||||
myOptions
|
||||
);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
} catch (e) {
|
||||
|
@ -209,19 +227,7 @@ module.exports = Self => {
|
|||
throw e;
|
||||
}
|
||||
|
||||
// TODO: create this email, use client-welcome as template. And view CALL mail_insert in redmine for the body
|
||||
// TODO: or use same funcionality back/methods/account/recover-password.js
|
||||
|
||||
// TODO: call worerWelcomeEmail, and this is who create the url for change password
|
||||
|
||||
const email = new Email('worker-welcome', {
|
||||
recipient: args.email,
|
||||
lang: ctx.req.getLocale()
|
||||
});
|
||||
|
||||
await email.send();
|
||||
|
||||
// return id, and in front use for redirection
|
||||
await models.Worker.workerWelcomeEmail(client.id);
|
||||
return client.id;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
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
|
||||
};
|
||||
};
|
|
@ -3,7 +3,6 @@
|
|||
<div class="grid-block vn-pa-ml">
|
||||
<h1>{{ $t('title', [id]) }}</h1>
|
||||
<p>{{ $t('description.dearWorker') }},</p>
|
||||
<p v-html="instructions"></p>
|
||||
<p>{{ $t('workerData', this.user.name, this.url) }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue
El campo se rellena en Access pero en el codigo no se utiliza para nada, seguir usandolo en Salix o quitarlo?
Eliminar campo