4658-createWorker #1236

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

View File

@ -1,22 +1,3 @@
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
VALUES
('ProfileType', '*', '*', 'ALLOW', 'ROLE', 'employee');
CREATE TABLE `vn`.`newWorkerConfig` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`street` VARCHAR(25) NULL,
`provinceFk` smallint(6) unsigned NULL,
`companyFk` smallint(5) unsigned NULL,
`profileTypeFk` INT(11) NULL,
`roleFk` int(10) unsigned NULL,
PRIMARY KEY (`id`),
CONSTRAINT `newWorkerConfig_province_fk` FOREIGN KEY (`provinceFk`) REFERENCES `vn`.`province` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `newWorkerConfig_company_fk` FOREIGN KEY (`companyFk`) REFERENCES `vn`.`company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `newWorkerConfig_profileType_fk` FOREIGN KEY (`profileTypeFk`) REFERENCES `vn`.`profileType` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `newWorkerConfig_role_fk` FOREIGN KEY (`roleFk`) REFERENCES `account`.`role` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
);
UPDATE `salix`.`ACL` UPDATE `salix`.`ACL`
SET accessType='READ' SET accessType='READ'
WHERE model='Worker' WHERE model='Worker'
@ -36,8 +17,8 @@ INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `pri
('Worker', 'new', 'WRITE', 'ALLOW', 'ROLE', 'hr'), ('Worker', 'new', 'WRITE', 'ALLOW', 'ROLE', 'hr'),
('Role', '*', 'READ', 'ALLOW', 'ROLE', 'hr'); ('Role', '*', 'READ', 'ALLOW', 'ROLE', 'hr');
/* ALTER TABLE `vn`.`workerConfig` ADD roleFk int(10) unsigned NOT NULL COMMENT 'Rol por defecto al dar de alta un trabajador nuevo';
INSERT INTO `vn`.`newWorkerConfig` (`id`, `street`, `provinceFk`, `companyFk`, `profileTypeFk`, `roleFk`) UPDATE `vn`.`workerConfig`
VALUES SET roleFk = 1
(1, 'C/ ', 57, 442, 1, 1); WHERE id = 1;
*/

View File

@ -2769,3 +2769,7 @@ INSERT INTO `vn`.`payDemDetail` (`id`, `detail`)
VALUES VALUES
(1, 1); (1, 1);
INSERT INTO `vn`.`workerConfig` (`id`, `businessUpdated`, `roleFk`)
VALUES
(1, NULL, 1);

View File

@ -1,7 +1,7 @@
import selectors from '../../helpers/selectors.js'; import selectors from '../../helpers/selectors.js';
import getBrowser from '../../helpers/puppeteer'; import getBrowser from '../../helpers/puppeteer';
describe('Worker calendar path', () => { describe('Worker create path', () => {
let browser; let browser;
let page; let page;
let newWorker; let newWorker;
@ -23,13 +23,12 @@ describe('Worker calendar path', () => {
await page.write(selectors.workerCreate.fi, '78457139E'); await page.write(selectors.workerCreate.fi, '78457139E');
await page.write(selectors.workerCreate.phone, '12356789'); await page.write(selectors.workerCreate.phone, '12356789');
await page.write(selectors.workerCreate.postcode, '46680'); await page.write(selectors.workerCreate.postcode, '46680');
await page.write(selectors.workerCreate.street, 'Doomstadt'); await page.write(selectors.workerCreate.street, 'S/ Doomstadt');
await page.write(selectors.workerCreate.email, 'doctorDoom@marvel.com'); await page.write(selectors.workerCreate.email, 'doctorDoom@marvel.com');
await page.write(selectors.workerCreate.iban, 'ES9121000418450200051332'); await page.write(selectors.workerCreate.iban, 'ES9121000418450200051332');
await page.autocompleteSearch(selectors.workerCreate.switft, 'BBKKESMMMMM'); await page.autocompleteSearch(selectors.workerCreate.switft, 'BBKKESMMMMM');
});
it('should check for autocompleted worker code and worker user name', async() => { // should check for autocompleted worker code and worker user name
const workerCode = await page const workerCode = await page
.waitToGetProperty(selectors.workerCreate.code, 'value'); .waitToGetProperty(selectors.workerCreate.code, 'value');
@ -38,34 +37,30 @@ describe('Worker calendar path', () => {
expect(workerCode).toEqual('VVD'); expect(workerCode).toEqual('VVD');
expect(newWorker).toContain('victorvd'); expect(newWorker).toContain('victorvd');
});
it('should fail if necessary data is void', async() => { // should fail if necessary data is void
await page.waitToClick(selectors.workerCreate.createButton); await page.waitToClick(selectors.workerCreate.createButton);
const message = await page.waitForSnackbar(); let message = await page.waitForSnackbar();
expect(message.text).toContain('is a required argument'); expect(message.text).toContain('is a required argument');
});
it('should create a new worker and go to worker basic data', async() => { // should create a new worker and go to worker basic data'
await page.pickDate(selectors.workerCreate.birth, new Date(1962, 8, 5)); await page.pickDate(selectors.workerCreate.birth, new Date(1962, 8, 5));
await page.autocompleteSearch(selectors.workerCreate.role, 'Jefe de personal de reparto');
await page.autocompleteSearch(selectors.workerCreate.boss, 'deliveryBoss'); await page.autocompleteSearch(selectors.workerCreate.boss, 'deliveryBoss');
await page.waitToClick(selectors.workerCreate.createButton); await page.waitToClick(selectors.workerCreate.createButton);
const message = await page.waitForSnackbar(); message = await page.waitForSnackbar();
await page.waitForState('worker.card.basicData'); await page.waitForState('worker.card.basicData');
expect(message.text).toContain('Data saved!'); expect(message.text).toContain('Data saved!');
});
it('rollback', async() => { // 'rollback'
await page.loginAndModule('sysadmin', 'account'); await page.loginAndModule('sysadmin', 'account');
await page.accessToSearchResult(newWorker); await page.accessToSearchResult(newWorker);
await page.waitToClick(selectors.accountDescriptor.menuButton); await page.waitToClick(selectors.accountDescriptor.menuButton);
await page.waitToClick(selectors.accountDescriptor.deactivateUser); await page.waitToClick(selectors.accountDescriptor.deactivateUser);
await page.waitToClick(selectors.accountDescriptor.acceptButton); await page.waitToClick(selectors.accountDescriptor.acceptButton);
let message = await page.waitForSnackbar(); message = await page.waitForSnackbar();
expect(message.text).toContain('User deactivated!'); expect(message.text).toContain('User deactivated!');

View File

@ -1,8 +1,9 @@
/* eslint max-len: ["error", { "code": 130 }]*/
const UserError = require('vn-loopback/util/user-error'); const UserError = require('vn-loopback/util/user-error');
module.exports = Self => { module.exports = Self => {
Self.remoteMethodCtx('new', { Self.remoteMethodCtx('new', {
alexm marked this conversation as resolved
Review

canvia la descripcio

canvia la descripcio
description: 'Creates a new ticket and returns the id', description: 'Creates a new worker and returns the id',
accessType: 'WRITE', accessType: 'WRITE',
accepts: [ accepts: [
{ {
@ -35,12 +36,6 @@ module.exports = Self => {
description: `The worker email`, description: `The worker email`,
required: true, required: true,
}, },
{
arg: 'roleFk',
type: 'number',
description: `The worker role`,
required: true,
},
{ {
arg: 'street', arg: 'street',
type: 'string', type: 'string',
@ -106,12 +101,6 @@ module.exports = Self => {
type: 'date', type: 'date',
description: `The worker birth`, description: `The worker birth`,
required: true, required: true,
},
{
arg: 'profileTypeFk',
type: 'number',
description: `The worker profile type ¿DELETE?`,
required: true,
} }
], ],
returns: { returns: {
@ -150,6 +139,7 @@ module.exports = Self => {
if (!client) { if (!client) {
const nickname = args.firstName.concat(' ', args.lastNames); const nickname = args.firstName.concat(' ', args.lastNames);
const workerConfig = await models.WorkerConfig.findOne({fields: ['roleFk']});
const [randomPassword] = await models.Worker.rawSql( const [randomPassword] = await models.Worker.rawSql(
'SELECT account.passwordGenerate() as password;' 'SELECT account.passwordGenerate() as password;'
); );
@ -160,7 +150,7 @@ module.exports = Self => {
nickname, nickname,
password: randomPassword.password, password: randomPassword.password,
email: args.email, email: args.email,
role: args.roleFk, roleFk: workerConfig.roleFk,
}, },
myOptions myOptions
); );
@ -198,13 +188,17 @@ module.exports = Self => {
provinceFk: args.provinceFk, provinceFk: args.provinceFk,
postalCode: args.postalCode, postalCode: args.postalCode,
mobile: args.phone, mobile: args.phone,
nickname: 'TR ' + nickname, nickname: nickname,
isDefaultAddress: true, isDefaultAddress: true,
}, },
myOptions myOptions
); );
client = await models.Client.findById(user.id, null, myOptions); client = await models.Client.findById(
user.id,
{fields: ['id', 'name', 'socialName', 'street', 'city', 'iban', 'bankEntityFk', 'defaultAddressFk']},
myOptions
);
await client.updateAttributes( await client.updateAttributes(
{ {

View File

@ -24,7 +24,6 @@ describe('Worker new', () => {
firstName: 'default', firstName: 'default',
lastNames: 'worker', lastNames: 'worker',
email: 'defaultWorker@mydomain.com', email: 'defaultWorker@mydomain.com',
roleFk: 1,
street: 'S/ defaultWorkerStreet', street: 'S/ defaultWorkerStreet',
city: 'defaultWorkerCity', city: 'defaultWorkerCity',
provinceFk: 1, provinceFk: 1,

View File

@ -26,9 +26,6 @@
"Journey": { "Journey": {
"dataSource": "vn" "dataSource": "vn"
}, },
"NewWorkerConfig":{
"dataSource": "vn"
},
"ProfileType":{ "ProfileType":{
"dataSource": "vn" "dataSource": "vn"
}, },
@ -41,36 +38,42 @@
"WorkCenterHoliday": { "WorkCenterHoliday": {
"dataSource": "vn" "dataSource": "vn"
}, },
"WorkerDms": { "Worker": {
"dataSource": "vn" "dataSource": "vn"
}, },
"Worker": { "WorkerConfig": {
"dataSource": "vn"
},
"WorkerDepartment": {
"dataSource": "vn"
},
"WorkerDisableExcluded": {
"dataSource": "vn"
},
"WorkerDms": {
"dataSource": "vn" "dataSource": "vn"
}, },
"WorkerLabour": { "WorkerLabour": {
"dataSource": "vn" "dataSource": "vn"
}, },
"WorkerLog": {
"dataSource": "vn"
},
"WorkerMana": { "WorkerMana": {
"dataSource": "vn" "dataSource": "vn"
}, },
"WorkerMedia": {
"dataSource": "vn"
},
"WorkerTeam": { "WorkerTeam": {
"dataSource": "vn" "dataSource": "vn"
}, },
"WorkerTeamCollegues": { "WorkerTeamCollegues": {
"dataSource": "vn" "dataSource": "vn"
}, },
"WorkerMedia": {
"dataSource": "vn"
},
"WorkerDepartment": {
"dataSource": "vn"
},
"WorkerTimeControl": { "WorkerTimeControl": {
"dataSource": "vn" "dataSource": "vn"
}, },
"WorkerLog": {
"dataSource": "vn"
},
"WorkerTimeControlConfig": { "WorkerTimeControlConfig": {
"dataSource": "vn" "dataSource": "vn"
}, },
@ -79,9 +82,6 @@
}, },
"WorkerTimeControlMail": { "WorkerTimeControlMail": {
"dataSource": "vn" "dataSource": "vn"
},
"WorkerDisableExcluded": {
"dataSource": "vn"
} }
} }

View File

@ -1,9 +1,9 @@
{ {
"name": "NewWorkerConfig", "name": "WorkerConfig",
"base": "VnModel", "base": "VnModel",
"options": { "options": {
"mysql": { "mysql": {
"table": "newWorkerConfig" "table": "workerConfig"
} }
}, },
"properties": { "properties": {
@ -12,18 +12,6 @@
"id": true, "id": true,
"description": "Identifier" "description": "Identifier"
}, },
"street": {
"type": "string"
},
"provinceFk": {
"type": "number"
},
"companyFk": {
"type": "number"
},
"profileTypeFk": {
"type": "number"
},
"roleFk": { "roleFk": {
"type": "number" "type": "number"
} }

View File

@ -52,19 +52,9 @@
</vn-textfield> </vn-textfield>
</vn-horizontal> </vn-horizontal>
<vn-horizontal> <vn-horizontal>
<vn-autocomplete
vn-id="province"
label="Province"
ng-model="$ctrl.worker.provinceFk"
selection="$ctrl.province"
url="Provinces/location"
fields="['id', 'name', 'countryFk']"
rule>
<tpl-item>{{name}} ({{country.country}})</tpl-item>
</vn-autocomplete>
<vn-datalist <vn-datalist
label="Postcode" label="Postcode"
vn-two vn-one
ng-model="$ctrl.worker.postcode" ng-model="$ctrl.worker.postcode"
selection="$ctrl.postcode" selection="$ctrl.postcode"
url="Postcodes/location" url="Postcodes/location"
@ -87,6 +77,16 @@
</vn-icon-button> </vn-icon-button>
</append> </append>
</vn-datalist> </vn-datalist>
<vn-autocomplete
vn-id="province"
label="Province"
ng-model="$ctrl.worker.provinceFk"
selection="$ctrl.province"
url="Provinces/location"
fields="['id', 'name', 'countryFk']"
rule>
<tpl-item>{{name}} ({{country.country}})</tpl-item>
</vn-autocomplete>
</vn-horizontal> </vn-horizontal>
<vn-horizontal> <vn-horizontal>
<vn-datalist <vn-datalist
@ -120,14 +120,6 @@
ng-model="$ctrl.worker.email" ng-model="$ctrl.worker.email"
rule> rule>
</vn-textfield> </vn-textfield>
<vn-autocomplete
label="Access permission"
ng-model="$ctrl.worker.roleFk"
value-field="id"
show-field="description"
url="Roles"
rule>
</vn-autocomplete>
</vn-horizontal> </vn-horizontal>
<vn-horizontal> <vn-horizontal>
<vn-autocomplete <vn-autocomplete
@ -148,15 +140,6 @@
where="{role: 'employee'}" where="{role: 'employee'}"
label="Boss"> label="Boss">
</vn-autocomplete> </vn-autocomplete>
<vn-autocomplete
vn-one
vn-id="profileType"
ng-model="$ctrl.worker.profileTypeFk"
url="ProfileTypes"
show-field="name"
value-field="id"
label="ProfileType">
</vn-autocomplete>
</vn-horizontal> </vn-horizontal>
<vn-horizontal> <vn-horizontal>
<vn-textfield <vn-textfield

View File

@ -4,9 +4,7 @@ import Section from 'salix/components/section';
export default class Controller extends Section { export default class Controller extends Section {
constructor($element, $) { constructor($element, $) {
super($element, $); super($element, $);
this.$http.get('NewWorkerConfigs/findOne').then(res => { this.worker = {companyFk: this.vnConfig.user.companyFk};
return this.worker = Object.assign({}, res.data);
});
} }
onSubmit() { onSubmit() {
@ -45,6 +43,9 @@ export default class Controller extends Section {
this.worker.code = newCode.toUpperCase().slice(0, 3); this.worker.code = newCode.toUpperCase().slice(0, 3);
this.worker.name = totalNameArray[0] + newCode.slice(1); this.worker.name = totalNameArray[0] + newCode.slice(1);
if (!this.worker.companyFk)
this.worker.companyFk = this.vnConfig.user.companyFk;
} }
get province() { get province() {

View File

@ -23,6 +23,7 @@ describe('Worker', () => {
const $element = angular.element('<vn-worker-create></vn-worker-create>'); const $element = angular.element('<vn-worker-create></vn-worker-create>');
controller = $componentController('vnWorkerCreate', {$element, $scope}); controller = $componentController('vnWorkerCreate', {$element, $scope});
controller.worker = {}; controller.worker = {};
controller.vnConfig = {user: {companyFk: 1}};
})); }));
describe('onSubmit()', () => { describe('onSubmit()', () => {
@ -115,7 +116,7 @@ describe('Worker', () => {
}); });
describe('generateCodeUser()', () => { describe('generateCodeUser()', () => {
it(`should generate worker code and name `, () => { it(`should generate worker code, name and company `, () => {
controller.worker = { controller.worker = {
firstName: 'default', firstName: 'default',
lastNames: 'generate worker' lastNames: 'generate worker'
@ -125,6 +126,7 @@ describe('Worker', () => {
expect(controller.worker.code).toEqual('DGW'); expect(controller.worker.code).toEqual('DGW');
expect(controller.worker.name).toEqual('defaultgw'); expect(controller.worker.name).toEqual('defaultgw');
expect(controller.worker.companyFk).toEqual(controller.vnConfig.user.companyFk);
}); });
}); });
}); });