4658-createWorker #1236

Merged
alexm merged 35 commits from 4658-createWorker into dev 2023-01-23 07:30:52 +00:00
7 changed files with 188 additions and 17 deletions
Showing only changes of commit aa5cfde1ae - Show all commits

View File

@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- [General](Inicio) Permite recuperar la contraseña
- [Trabajadores](Nuevo trabajador) Nueva sección
### Changed

View File

@ -934,10 +934,10 @@ INSERT INTO `vn`.`expedition`(`id`, `agencyModeFk`, `ticketFk`, `freightItemFk`,
(7, 2, 4, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH), 1, 18, NULL, 94, NULL,NULL),
(8, 3, 5, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH), 1, 18, NULL, 94, 1, NULL),
(9, 3, 6, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 18, NULL, 94, 2, NULL),
(10, 7, 7, 71, NOW(), 1, 18, NULL, 94, 3, NULL),
(11, 7, 8, 71, NOW(), 1, 18, NULL, 94, 3, NULL),
(12, 7, 9, 71, NOW(), 1, 18, NULL, 94, 3, NULL),
(13, 1, 10,71, NOW(), 1, 18, NULL, 94, 3, NULL);
(10, 7, 7, 71, util.VN_NOW(), 1, 18, NULL, 94, 3, NULL),
(11, 7, 8, 71, util.VN_NOW(), 1, 18, NULL, 94, 3, NULL),
(12, 7, 9, 71, util.VN_NOW(), 1, 18, NULL, 94, 3, NULL),
(13, 1, 10,71, util.VN_NOW(), 1, 18, NULL, 94, 3, NULL);
INSERT INTO `vn`.`expeditionState`(`id`, `created`, `expeditionFk`, `typeFk`, `userFk`)
@ -1910,7 +1910,7 @@ DROP TEMPORARY TABLE IF EXISTS tmp.worker;
CREATE TEMPORARY TABLE tmp.worker
(PRIMARY KEY (id))
ENGINE = MEMORY
SELECT w.id, w.id as `workerFk`, 'VNL', CONCAT(YEAR(DATE_ADD(CURDATE(), INTERVAL -1 YEAR)), '-12-25'), CONCAT(YEAR(DATE_ADD(CURDATE(), INTERVAL +1 YEAR)), '-12-25'), CONCAT('E-46-', RPAD(CONCAT(w.id, 9), 8, w.id)), NULL as `notes`, NULL as `departmentFk`, 23, 1 as `workerBusinessProfessionalCategoryFk`, 1 as `calendarTypeFk`, 1 as `isHourlyLabor`, 1 as `workerBusinessAgreementFk`, 1 as `workcenterFk`
SELECT w.id, w.id as `workerFk`, 'VNL', CONCAT(YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 YEAR)), '-12-25'), CONCAT(YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL +1 YEAR)), '-12-25'), CONCAT('E-46-', RPAD(CONCAT(w.id, 9), 8, w.id)), NULL as `notes`, NULL as `departmentFk`, 23, 1 as `workerBusinessProfessionalCategoryFk`, 1 as `calendarTypeFk`, 1 as `isHourlyLabor`, 1 as `workerBusinessAgreementFk`, 1 as `workcenterFk`
FROM `vn`.`worker` `w`;
INSERT INTO `vn`.`business`(`id`, `workerFk`, `companyCodeFk`, `started`, `ended`, `workerBusiness`, `reasonEndFk`, `notes`, `departmentFk`, `workerBusinessProfessionalCategoryFk`, `calendarTypeFk`, `isHourlyLabor`, `workerBusinessAgreementFk`, `workcenterFk`)
@ -1920,7 +1920,7 @@ DROP TEMPORARY TABLE IF EXISTS tmp.worker;
CREATE TEMPORARY TABLE tmp.worker
(PRIMARY KEY (id))
ENGINE = MEMORY
SELECT '1111' as 'id', w.id as `workerFk`, 'VNL', CONCAT(YEAR(DATE_ADD(CURDATE(), INTERVAL -2 YEAR)), '-12-25'), CONCAT(YEAR(DATE_ADD(CURDATE(), INTERVAL -1 YEAR)), '-12-24'), CONCAT('E-46-', RPAD(CONCAT(w.id, 9), 8, w.id)), NULL as `notes`, NULL as `departmentFk`, 23, 1 as `workerBusinessProfessionalCategoryFk`, 1 as `calendarTypeFk`, 1 as `isHourlyLabor`, 1 as `workerBusinessAgreementFk`, 1 as `workcenterFk`
SELECT '1111' as 'id', w.id as `workerFk`, 'VNL', CONCAT(YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -2 YEAR)), '-12-25'), CONCAT(YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 YEAR)), '-12-24'), CONCAT('E-46-', RPAD(CONCAT(w.id, 9), 8, w.id)), NULL as `notes`, NULL as `departmentFk`, 23, 1 as `workerBusinessProfessionalCategoryFk`, 1 as `calendarTypeFk`, 1 as `isHourlyLabor`, 1 as `workerBusinessAgreementFk`, 1 as `workcenterFk`
FROM `vn`.`worker` `w`
WHERE `w`.`id` = 1109;
@ -2633,7 +2633,7 @@ INSERT INTO `vn`.`machineWorker` (`workerFk`, `machineFk`, `inTimed`, `outTimed`
INSERT INTO `vn`.`zoneExclusion` (`id`, `zoneFk`, `dated`, `created`, `userFk`)
VALUES
(1, 1, DATE_ADD(CURDATE(), INTERVAL (IF(DAYOFWEEK(CURDATE())<=7, 7, 14) - DAYOFWEEK(util.VN_CURDATE())) DAY), util.VN_CURDATE(), 100),
(1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL (IF(DAYOFWEEK(util.VN_CURDATE())<=7, 7, 14) - DAYOFWEEK(util.VN_CURDATE())) DAY), util.VN_CURDATE(), 100),
(2, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL (IF(DAYOFWEEK(util.VN_CURDATE())<=8, 8, 15) - DAYOFWEEK(util.VN_CURDATE())) DAY), util.VN_CURDATE(), 100);
INSERT INTO `vn`.`zoneExclusionGeo` (`zoneExclusionFk`, `geoFk`)

View File

@ -1,6 +1,6 @@
Reset password: Restrablecer contraseña
New password: Nueva contraseña
Repeat password: Repetir contraseñaç
Repeat password: Repetir contraseña
Password changed!: ¡Contraseña cambiada!
Password requirements: >
La contraseña debe tener al menos {{ length }} caracteres de longitud,

View File

@ -1,4 +1,3 @@
const md5 = require('md5');
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
@ -108,6 +107,12 @@ module.exports = Self => {
description: `The worker birth`,
required: true,
},
{
arg: 'profileTypeFk',
alexm marked this conversation as resolved Outdated
Outdated
Review

El campo se rellena en Access pero en el codigo no se utiliza para nada, seguir usandolo en Salix o quitarlo?

El campo se rellena en Access pero en el codigo no se utiliza para nada, seguir usandolo en Salix o quitarlo?

Eliminar campo

Eliminar campo
type: 'number',
description: `The worker profile type ¿DELETE?`,
required: true,
}
],
returns: {
type: 'number',
@ -134,6 +139,7 @@ module.exports = Self => {
}
let client;
try {
client = await models.Client.findOne(
{
@ -144,14 +150,15 @@ module.exports = Self => {
if (!client) {
const nickname = args.firstName.concat(' ', args.lastNames);
const randomPassword = await models.Worker.rawSql(
'SELECT account.passwordGenerate();'
const [randomPassword] = await models.Worker.rawSql(
'SELECT account.passwordGenerate() as password;'
);
const user = await models.Account.create(
{
name: args.name,
nickname,
password: md5(randomPassword),
password: randomPassword.password,
email: args.email,
role: args.roleFk,
alexm marked this conversation as resolved Outdated

preguntar a laboral si lo quitamos de la creacion.
Preguntar si al crearlo alguna vez ponen algo distinto a employee

preguntar a laboral si lo quitamos de la creacion. Preguntar si al crearlo alguna vez ponen algo distinto a employee
Outdated
Review

Quitar

Quitar
},
@ -208,6 +215,10 @@ module.exports = Self => {
myOptions
);
}
const user = await models.Account.findById(client.id, null, myOptions);
await user.updateAttribute('email', args.email, myOptions);
await models.Worker.rawSql(
'CALL vn.workerCreate(?, ?, ?, ?, ?, ?, ?)',
[
@ -223,10 +234,10 @@ module.exports = Self => {
);
if (tx) await tx.commit();
} catch (err) {
} catch (error) {
if (tx) await tx.rollback();
const code = err.code;
const message = err.sqlMessage;
const code = error.code;
const message = error.sqlMessage;
if (code === 'ER_DUP_ENTRY' && message.includes(`for key 'mail'`))
throw new UserError(`This personal mail already exists`);
@ -237,7 +248,7 @@ module.exports = Self => {
if (code === 'ER_DUP_ENTRY' && message.includes(`PRIMARY`))
throw new UserError(`This worker already exists`);
throw err;
throw error;
}
await models.user.resetPassword({

View File

@ -0,0 +1,140 @@
const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
describe('Worker new', () => {
beforeAll(async() => {
const activeCtx = {
accessToken: {userId: 9},
http: {
req: {
headers: {origin: 'http://localhost'}
}
}
};
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
});
const employeeId = 1;
const defaultWorker = {
fi: '78457139E',
name: 'defaultWorker',
firstName: 'default',
lastNames: 'worker',
email: 'defaultWorker@mydomain.com',
roleFk: 1,
street: 'S/ defaultWorkerStreet',
city: 'defaultWorkerCity',
provinceFk: 1,
iban: 'ES8304879798578129532677',
bankEntityFk: 128,
companyFk: 442,
postcode: '46680',
phone: '633342693',
code: 'DWW',
bossFk: 9,
birth: '2022-12-11T23:00:00.000Z'
};
it('should return error if personal mail already exists', async() => {
const user = await models.Account.findById(employeeId, {fields: ['email']});
const tx = await models.Worker.beginTransaction({});
let error;
try {
const options = {transaction: tx};
const ctx = {
args: Object.assign({}, defaultWorker, {email: user.email})
};
await models.Worker.new(ctx, options);
await tx.rollback();
} catch (e) {
error = e;
await tx.rollback();
}
expect(error.message).toEqual('This personal mail already exists');
});
it('should return error if worker code already exists', async() => {
const worker = await models.Worker.findById(employeeId, {fields: ['code']});
const tx = await models.Worker.beginTransaction({});
let error;
try {
const options = {transaction: tx};
const ctx = {
args: Object.assign({}, defaultWorker, {code: worker.code})
};
await models.Worker.new(ctx, options);
await tx.rollback();
} catch (e) {
error = e;
await tx.rollback();
}
expect(error.message).toEqual('This worker code already exists');
});
it('should return error if worker already exists', async() => {
const worker = await models.Client.findById(employeeId, {fields: ['fi']});
const tx = await models.Worker.beginTransaction({});
let error;
try {
const options = {transaction: tx};
const ctx = {
args: Object.assign({}, defaultWorker, {fi: worker.fi})
};
await models.Worker.new(ctx, options);
await tx.rollback();
} catch (e) {
error = e;
await tx.rollback();
}
expect(error.message).toEqual('This worker already exists');
});
it('should create a new worker', async() => {
const newWorker = await models.Worker.new({args: defaultWorker});
await models.Worker.destroyById(newWorker.id);
await models.Address.destroyAll({clientFk: newWorker.id});
await models.Mandate.destroyAll({clientFk: newWorker.id});
await models.Client.destroyById(newWorker.id);
await models.Account.destroyById(newWorker.id);
expect(newWorker.id).toBeDefined();
});
it('should create a new worker in client', async() => {
const bruceWayneId = 1101;
const client = await models.Client.findById(bruceWayneId, {fields: ['fi', 'email']});
const newWorkerData = {
args: Object.assign(
{},
defaultWorker,
{
fi: client.fi,
email: client.email
})
};
const newWorker = await models.Worker.new(newWorkerData);
await models.Worker.destroyById(newWorker.id);
expect(newWorker.id).toEqual(bruceWayneId);
});
});

View File

@ -7,6 +7,26 @@ export default class Controller extends Section {
this.$http.get('NewWorkerConfigs/findOne').then(res => {
return this.worker = Object.assign({}, res.data);
});
// DELETE
this.worker = {
fi: '73226971P',
name: 'ASDASD',
firstName: 'Test',
lastNames: 'Test',
email: 'developer4@mydomain.com',
roleFk: 1,
street: 'S/ ',
city: 'asd',
provinceFk: 1,
iban: 'ES2420386579855387888566',
bankEntityFk: 128,
companyFk: 442,
postcode: 'asd',
phone: '633342693',
code: 'ASD',
bossFk: 34,
birth: '2022-12-11T23:00:00.000Z'
};
}
onSubmit() {

View File

@ -5,7 +5,6 @@ module.exports = {
name: 'worker-welcome',
async serverPrefetch() {
this.worker = await this.fetchWorker(this.id);
console.log(this.url);
},
methods: {
fetchWorker(id) {