feat: handle errors and autogenerate user and code
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
b378598113
commit
156f2b9129
|
@ -247,7 +247,10 @@
|
|||
"Empty data source": "Origen de datos vacio",
|
||||
"Email verify": "Correo de verificación",
|
||||
"Landing cannot be lesser than shipment": "Landing cannot be lesser than shipment",
|
||||
"Receipt's bank was not found": "No se encontró el banco del recibo",
|
||||
"This receipt was not compensated": "Este recibo no ha sido compensado",
|
||||
"Client's email was not found": "No se encontró el email del cliente"
|
||||
"Receipt's bank was not found": "No se encontró el banco del recibo",
|
||||
"This receipt was not compensated": "Este recibo no ha sido compensado",
|
||||
"Client's email was not found": "No se encontró el email del cliente",
|
||||
"This worker code already exists": "Este codigo de trabajador ya existe",
|
||||
"This personal mail already exists": "Este correo personal ya existe",
|
||||
"This worker already exists": "Este trabajador ya existe"
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const md5 = require('md5');
|
||||
const UserError = require('vn-loopback/util/user-error');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('new', {
|
||||
|
@ -8,103 +9,103 @@ module.exports = Self => {
|
|||
{
|
||||
arg: 'fi',
|
||||
type: 'string',
|
||||
description: `The fi of worker`,
|
||||
description: `The worker fi`,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'name',
|
||||
type: 'string',
|
||||
description: `REPLACE!`,
|
||||
description: `The user name`,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'firstName',
|
||||
type: 'string',
|
||||
description: `REPLACE!`,
|
||||
description: `The worker firstname`,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'lastNames',
|
||||
type: 'string',
|
||||
description: `REPLACE!`,
|
||||
description: `The worker lastnames`,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'email',
|
||||
type: 'string',
|
||||
description: `REPLACE!`,
|
||||
description: `The worker email`,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'roleFk',
|
||||
type: 'number',
|
||||
description: `REPLACE!`,
|
||||
description: `The worker role`,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'street',
|
||||
type: 'string',
|
||||
description: `REPLACE!`,
|
||||
description: `The worker address`,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'city',
|
||||
type: 'string',
|
||||
description: `REPLACE!`,
|
||||
description: `The worker city`,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'provinceFk',
|
||||
type: 'number',
|
||||
description: `REPLACE!`,
|
||||
description: `The worker province`,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'iban',
|
||||
type: 'string',
|
||||
description: `REPLACE!`,
|
||||
description: `The worker iban`,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'bankEntityFk',
|
||||
type: 'number',
|
||||
description: `REPLACE!`,
|
||||
description: `The worker bank entity`,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'companyFk',
|
||||
type: 'number',
|
||||
description: `REPLACE!`,
|
||||
description: `The worker company`,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'postcode',
|
||||
type: 'string',
|
||||
description: `REPLACE!`,
|
||||
description: `The worker postcode`,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'phone',
|
||||
type: 'string',
|
||||
description: `REPLACE!`,
|
||||
description: `The worker phone`,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'code',
|
||||
type: 'string',
|
||||
description: `REPLACE!`,
|
||||
description: `The worker code`,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'bossFk',
|
||||
type: 'number',
|
||||
description: `REPLACE!`,
|
||||
description: `The worker boss`,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'birth',
|
||||
type: 'date',
|
||||
description: `REPLACE!`,
|
||||
description: `The worker birth`,
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
|
@ -152,7 +153,7 @@ module.exports = Self => {
|
|||
nickname,
|
||||
password: md5(randomPassword),
|
||||
email: args.email,
|
||||
role: args.role,
|
||||
role: args.roleFk,
|
||||
},
|
||||
myOptions
|
||||
);
|
||||
|
@ -222,10 +223,21 @@ module.exports = Self => {
|
|||
);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
} catch (e) {
|
||||
} catch (err) {
|
||||
if (tx) await tx.rollback();
|
||||
console.log(e);
|
||||
throw e;
|
||||
const code = err.code;
|
||||
const message = err.sqlMessage;
|
||||
|
||||
if (code === 'ER_DUP_ENTRY' && message.includes(`for key 'mail'`))
|
||||
throw new UserError(`This personal mail already exists`);
|
||||
|
||||
if (code === 'ER_DUP_ENTRY' && message.includes(`CodigoTrabajador_UNIQUE`))
|
||||
throw new UserError(`This worker code already exists`);
|
||||
|
||||
if (code === 'ER_DUP_ENTRY' && message.includes(`PRIMARY`))
|
||||
throw new UserError(`This worker already exists`);
|
||||
|
||||
throw err;
|
||||
}
|
||||
|
||||
await models.user.resetPassword({
|
||||
|
|
|
@ -13,11 +13,13 @@
|
|||
label="Firstname"
|
||||
ng-model="$ctrl.worker.firstName"
|
||||
rule
|
||||
on-change="$ctrl.generateCodeUser()"
|
||||
vn-focus>
|
||||
</vn-textfield>
|
||||
<vn-textfield
|
||||
vn-one
|
||||
label="Lastname"
|
||||
on-change="$ctrl.generateCodeUser()"
|
||||
ng-model="$ctrl.worker.lastNames"
|
||||
rule>
|
||||
</vn-textfield>
|
||||
|
@ -38,6 +40,8 @@
|
|||
vn-one
|
||||
label="Code"
|
||||
ng-model="$ctrl.worker.code"
|
||||
maxLength="3"
|
||||
on-change="$ctrl.worker.code = $ctrl.worker.code.toUpperCase()"
|
||||
rule>
|
||||
</vn-textfield>
|
||||
<vn-textfield
|
||||
|
@ -107,15 +111,14 @@
|
|||
</vn-horizontal>
|
||||
<vn-horizontal>
|
||||
<vn-textfield
|
||||
label="User"
|
||||
label="Web user"
|
||||
ng-model="$ctrl.worker.name"
|
||||
rule>
|
||||
</vn-textfield>
|
||||
<vn-textfield
|
||||
label="Personal email"
|
||||
ng-model="$ctrl.worker.email"
|
||||
rule
|
||||
info="You can save multiple emails">
|
||||
rule>
|
||||
</vn-textfield>
|
||||
<vn-autocomplete
|
||||
label="Access permission"
|
||||
|
|
|
@ -33,6 +33,20 @@ export default class Controller extends Section {
|
|||
});
|
||||
}
|
||||
|
||||
generateCodeUser() {
|
||||
if (!this.worker.firstName || !this.worker.lastNames) return;
|
||||
|
||||
const totalName = this.worker.firstName.concat(' ' + this.worker.lastNames).toLowerCase();
|
||||
const totalNameArray = totalName.split(' ');
|
||||
let newCode = '';
|
||||
|
||||
for (let part of totalNameArray)
|
||||
newCode += part.charAt(0);
|
||||
|
||||
this.worker.code = newCode.toUpperCase().slice(0, 3);
|
||||
this.worker.name = totalNameArray[0] + newCode.slice(1);
|
||||
}
|
||||
|
||||
get province() {
|
||||
return this._province;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
Name: Nombre
|
||||
Tax number: NIF/CIF
|
||||
Business name: Razón social
|
||||
Firstname: Nombre
|
||||
Lastname: Apellidos
|
||||
Fi: DNI/NIF/NIE
|
||||
Birth: Fecha de nacimiento
|
||||
Code: Código de trabajador
|
||||
Province: Provincia
|
||||
City: Población
|
||||
ProfileType: Tipo de perfil
|
||||
Street: Dirección
|
||||
Postcode: Código postal
|
||||
Web user: Usuario Web
|
||||
Email: E-mail
|
||||
Create and edit: Crear y editar
|
||||
You can save multiple emails: >-
|
||||
Puede guardar varios correos electrónicos encadenándolos mediante comas
|
||||
sin espacios, ejemplo: user@dominio.com, user2@dominio.com siendo el primer
|
||||
correo electrónico el principal
|
||||
The type of business must be filled in basic data: El tipo de negocio debe estar rellenado en datos básicos
|
||||
Access permission: Permiso de acceso
|
||||
|
|
Loading…
Reference in New Issue