feat: workerDisableExcluded update DB field
gitea/salix/pipeline/head Something is wrong with the build of this commit Details

This commit is contained in:
Pau 2022-10-06 10:18:08 +02:00
parent 600dd7a434
commit 1165e050eb
7 changed files with 112 additions and 41 deletions

View File

@ -0,0 +1,30 @@
module.exports = Self => {
Self.remoteMethod('workerDisableExcluded', {
description: 'Check if the worker can be disabled',
accessType: 'READ',
accepts: {
arg: 'id',
type: 'Number',
required: true,
description: `The worker id`,
http: {source: 'path'}
},
returns: {
type: 'boolean',
root: true
},
http: {
path: `/workerDisableExcluded/:id`,
verb: 'GET'
}
});
Self.workerDisableExcluded = async id => {
let result;
const query = `Select * from vn.workerDisableExcluded where workerFk like ${id}`;
let sqlResult = await Self.rawSql(query);
sqlResult.length == 0 ? result = false : result = true;
return result;
};
};

View File

@ -0,0 +1,45 @@
module.exports = Self => {
Self.remoteMethod('workerExcludeFromDisable', {
description: 'Change the status of the worker between can be disabled and cant be disabled',
accessType: 'READ',
accepts: [{
arg: 'id',
type: 'Number',
required: true,
description: `The worker id`,
http: {source: 'path'}
},
{
arg: 'currValue',
type: 'Boolean',
required: true,
description: `The current value of workerDisableExcluded`,
http: {source: 'path'}
}],
returns: {
type: 'boolean',
root: true
},
http: {
path: `/workerExcludeFromDisable/:id/:currValue`,
verb: 'GET'
}
});
Self.workerExcludeFromDisable = async(id, currValue) => {
const models = Self.app.models;
if (!currValue) {
await models.WorkerDisableExcluded.create({
workerFk: id,
dated: new Date()
});
} else {
await models.WorkerDisableExcluded.remove({
workerFk: id
});
}
return false;
};
};

View File

@ -1,26 +0,0 @@
module.exports = Self => {
Self.remoteMethod('workerDisableExcluded', {
description: 'Check an email inbox and process it',
accessType: 'READ',
accepts: {
arg: 'workerFk',
type: 'Number',
required: true,
description: `The worker id`
},
returns: {
type: ['Object'],
root: true
},
http: {
path: `/workerDisableExcluded`,
verb: 'GET'
}
});
Self.workerDisableExcluded = workerFk => {
console.log(workerFk);
return 'tests123';
};
};

View File

@ -13,4 +13,6 @@ module.exports = Self => {
require('../methods/worker/contracts')(Self);
require('../methods/worker/holidays')(Self);
require('../methods/worker/activeContract')(Self);
require('../methods/worker/workerDisableExcluded')(Self);
require('../methods/worker/workerExcludeFromDisable')(Self);
};

View File

@ -7,9 +7,12 @@
}
},
"properties": {
"id": {
"workerFk": {
"id": true,
"type": "number"
},
"dated": {
"type": "date"
}
},
"acls": [

View File

@ -15,14 +15,19 @@
</div>
</slot-before>
<slot-menu>
<label class="vn-item">
<!--
<input ng-if="$ctrl.isExcluded()" type="checkbox" id="canBeDisabled" disabled checked>
<input ng-if="!$ctrl.isExcluded()" type="checkbox" id="canBeDisabled" disabled>
-->
<p>{{$ctrl.isExcluded()}}</p>
</label>
<!--ng-if="!$ctrl.canBeExcluded"-->
<vn-item
ng-click="$ctrl.setExcluded()"
translate
ng-if="!$ctrl.excluded">
Marcar para no deshabilitar
</vn-item>
<vn-item
ng-click="$ctrl.setExcluded()"
translate
ng-if="$ctrl.excluded">
Marcar como deshabilitable
</vn-item>
</slot-menu>
<slot-body>
<div class="attributes">

View File

@ -5,6 +5,7 @@ class Controller extends Descriptor {
constructor($element, $, $rootScope) {
super($element, $);
this.$rootScope = $rootScope;
this.canBeExcluded();
}
get worker() {
@ -15,12 +16,23 @@ class Controller extends Descriptor {
this.entity = value;
}
async isExcluded() {
// eslint-disable-next-line no-console
console.log(this.entity);
let excluded = await this.$http.get(`workerDisableExcluded`);
// eslint-disable-next-line no-console
console.log(excluded);
get excluded() {
return this.entity.excluded;
}
set excluded(value) {
this.entity.excluded = value;
}
async canBeExcluded() {
await new Promise(r => setTimeout(r, 1000));
let data = await this.$http.get(`Workers/workerDisableExcluded/${this.entity.id}`);
this.excluded = data.data;
}
async setExcluded() {
await this.$http.get(`Workers/workerExcludeFromDisable/${this.entity.id}/${this.entity.excluded}`);
this.canBeExcluded();
}
loadData() {