4658-createWorker #1236
|
@ -1,5 +1,4 @@
|
||||||
const md5 = require('md5');
|
const md5 = require('md5');
|
||||||
const {Email} = require('vn-print');
|
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('new', {
|
Self.remoteMethodCtx('new', {
|
||||||
|
@ -10,113 +9,113 @@ module.exports = Self => {
|
||||||
arg: 'fi',
|
arg: 'fi',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
description: `The fi of worker`,
|
description: `The fi of worker`,
|
||||||
required: true
|
required: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'name',
|
arg: 'name',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
description: `REPLACE!`,
|
description: `REPLACE!`,
|
||||||
required: true
|
required: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'firstName',
|
arg: 'firstName',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
description: `REPLACE!`,
|
description: `REPLACE!`,
|
||||||
required: true
|
required: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'lastNames',
|
arg: 'lastNames',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
description: `REPLACE!`,
|
description: `REPLACE!`,
|
||||||
required: true
|
required: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'email',
|
arg: 'email',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
description: `REPLACE!`,
|
description: `REPLACE!`,
|
||||||
required: true
|
required: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'roleFk',
|
arg: 'roleFk',
|
||||||
type: 'number',
|
type: 'number',
|
||||||
description: `REPLACE!`,
|
description: `REPLACE!`,
|
||||||
required: true
|
required: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'street',
|
arg: 'street',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
description: `REPLACE!`,
|
description: `REPLACE!`,
|
||||||
required: true
|
required: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'city',
|
arg: 'city',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
description: `REPLACE!`,
|
description: `REPLACE!`,
|
||||||
required: true
|
required: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'provinceFk',
|
arg: 'provinceFk',
|
||||||
type: 'number',
|
type: 'number',
|
||||||
description: `REPLACE!`,
|
description: `REPLACE!`,
|
||||||
required: true
|
required: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'iban',
|
arg: 'iban',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
description: `REPLACE!`,
|
description: `REPLACE!`,
|
||||||
required: true
|
required: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'bankEntityFk',
|
arg: 'bankEntityFk',
|
||||||
type: 'number',
|
type: 'number',
|
||||||
description: `REPLACE!`,
|
description: `REPLACE!`,
|
||||||
required: true
|
required: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'companyFk',
|
arg: 'companyFk',
|
||||||
type: 'number',
|
type: 'number',
|
||||||
description: `REPLACE!`,
|
description: `REPLACE!`,
|
||||||
required: true
|
required: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'postcode',
|
arg: 'postcode',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
description: `REPLACE!`,
|
description: `REPLACE!`,
|
||||||
required: true
|
required: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'phone',
|
arg: 'phone',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
description: `REPLACE!`,
|
description: `REPLACE!`,
|
||||||
required: true
|
required: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'code',
|
arg: 'code',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
description: `REPLACE!`,
|
description: `REPLACE!`,
|
||||||
required: true
|
required: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'bossFk',
|
arg: 'bossFk',
|
||||||
type: 'number',
|
type: 'number',
|
||||||
description: `REPLACE!`,
|
description: `REPLACE!`,
|
||||||
required: true
|
required: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'birth',
|
arg: 'birth',
|
||||||
type: 'date',
|
type: 'date',
|
||||||
description: `REPLACE!`,
|
description: `REPLACE!`,
|
||||||
required: true
|
required: true,
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
returns: {
|
returns: {
|
||||||
alexm marked this conversation as resolved
Outdated
|
|||||||
type: 'number',
|
type: 'number',
|
||||||
root: true
|
root: true,
|
||||||
},
|
},
|
||||||
http: {
|
http: {
|
||||||
path: `/new`,
|
path: `/new`,
|
||||||
verb: 'POST'
|
verb: 'POST',
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.new = async(ctx, options) => {
|
Self.new = async(ctx, options) => {
|
||||||
|
@ -126,8 +125,7 @@ module.exports = Self => {
|
||||||
|
|
||||||
let tx;
|
let tx;
|
||||||
console.log(args);
|
console.log(args);
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object') Object.assign(myOptions, options);
|
||||||
Object.assign(myOptions, options);
|
|
||||||
|
|
||||||
if (!myOptions.transaction) {
|
if (!myOptions.transaction) {
|
||||||
tx = await Self.beginTransaction({});
|
tx = await Self.beginTransaction({});
|
||||||
|
@ -136,26 +134,38 @@ module.exports = Self => {
|
||||||
|
|
||||||
let client;
|
let client;
|
||||||
try {
|
try {
|
||||||
client = await models.Client.findOne({
|
client = await models.Client.findOne(
|
||||||
where: {fi: args.fi},
|
{
|
||||||
}, myOptions);
|
where: {fi: args.fi},
|
||||||
|
},
|
||||||
|
myOptions
|
||||||
|
);
|
||||||
|
|
||||||
if (!client) {
|
if (!client) {
|
||||||
const nickname = args.firstName.concat(' ', args.lastNames);
|
const nickname = args.firstName.concat(' ', args.lastNames);
|
||||||
const randomPassword = await models.Worker.rawSql('SELECT account.passwordGenerate();');
|
const randomPassword = await models.Worker.rawSql(
|
||||||
const user = await models.Account.create({
|
'SELECT account.passwordGenerate();'
|
||||||
name: args.name,
|
);
|
||||||
nickname,
|
const user = await models.Account.create(
|
||||||
password: md5(randomPassword),
|
{
|
||||||
email: args.email,
|
name: args.name,
|
||||||
role: args.role
|
nickname,
|
||||||
}, myOptions);
|
password: md5(randomPassword),
|
||||||
|
email: args.email,
|
||||||
|
role: args.role,
|
||||||
|
},
|
||||||
|
myOptions
|
||||||
|
);
|
||||||
|
|
||||||
await models.UserAccount.create({
|
await models.UserAccount.create(
|
||||||
id: user.id
|
{
|
||||||
}, myOptions);
|
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.firstName,
|
||||||
args.lastNames,
|
args.lastNames,
|
||||||
|
@ -167,31 +177,38 @@ module.exports = Self => {
|
||||||
args.companyFk,
|
args.companyFk,
|
||||||
args.phone,
|
args.phone,
|
||||||
args.email,
|
args.email,
|
||||||
user.id
|
user.id,
|
||||||
]
|
],
|
||||||
, myOptions);
|
myOptions
|
||||||
|
);
|
||||||
|
|
||||||
const address = await models.Address.create({
|
const address = await models.Address.create(
|
||||||
clientFk: user.id,
|
{
|
||||||
street: args.street,
|
clientFk: user.id,
|
||||||
city: args.city,
|
street: args.street,
|
||||||
provinceFk: args.provinceFk,
|
city: args.city,
|
||||||
postalCode: args.postalCode,
|
provinceFk: args.provinceFk,
|
||||||
mobile: args.phone,
|
postalCode: args.postalCode,
|
||||||
nickname: 'TR ' + nickname,
|
mobile: args.phone,
|
||||||
isDefaultAddress: true
|
nickname: 'TR ' + nickname,
|
||||||
}, myOptions);
|
isDefaultAddress: true,
|
||||||
|
},
|
||||||
|
myOptions
|
||||||
|
);
|
||||||
|
|
||||||
client = await models.Client.findById(user.id, null, myOptions);
|
client = await models.Client.findById(user.id, null, myOptions);
|
||||||
|
|
||||||
console.log(address.id);
|
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
|
|||||||
await client.updateAttributes({
|
{
|
||||||
iban: args.iban,
|
iban: args.iban,
|
||||||
bankEntityFk: args.bankEntityFk,
|
bankEntityFk: args.bankEntityFk,
|
||||||
defaultAddressFk: address.id
|
defaultAddressFk: address.id,
|
||||||
}, myOptions);
|
},
|
||||||
|
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.firstName,
|
||||||
args.lastNames,
|
args.lastNames,
|
||||||
|
@ -199,9 +216,10 @@ module.exports = Self => {
|
||||||
args.bossFk,
|
args.bossFk,
|
||||||
client.id,
|
client.id,
|
||||||
args.fi,
|
args.fi,
|
||||||
args.birth
|
args.birth,
|
||||||
]
|
],
|
||||||
, myOptions);
|
myOptions
|
||||||
|
);
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -209,19 +227,7 @@ module.exports = Self => {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: create this email, use client-welcome as template. And view CALL mail_insert in redmine for the body
|
await models.Worker.workerWelcomeEmail(client.id);
|
||||||
// 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
|
|
||||||
return 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">
|
<div class="grid-block vn-pa-ml">
|
||||||
<h1>{{ $t('title', [id]) }}</h1>
|
<h1>{{ $t('title', [id]) }}</h1>
|
||||||
<p>{{ $t('description.dearWorker') }},</p>
|
<p>{{ $t('description.dearWorker') }},</p>
|
||||||
<p v-html="instructions"></p>
|
|
||||||
<p>{{ $t('workerData', this.user.name, this.url) }}</p>
|
<p>{{ $t('workerData', this.user.name, this.url) }}</p>
|
||||||
</div>
|
</div>
|
||||||
</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