From 1165e050eb74cee4bc1e76fc9408ecd2de2b4753 Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Thu, 6 Oct 2022 10:18:08 +0200 Subject: [PATCH] feat: workerDisableExcluded update DB field --- .../methods/worker/workerDisableExcluded.js | 30 +++++++++++++ .../worker/workerExcludeFromDisable.js | 45 +++++++++++++++++++ .../workerDisableExclueded/checkExcluded.js | 26 ----------- modules/worker/back/models/worker.js | 2 + .../back/models/workerDisableExcluded.json | 5 ++- modules/worker/front/descriptor/index.html | 21 +++++---- modules/worker/front/descriptor/index.js | 24 +++++++--- 7 files changed, 112 insertions(+), 41 deletions(-) create mode 100644 modules/worker/back/methods/worker/workerDisableExcluded.js create mode 100644 modules/worker/back/methods/worker/workerExcludeFromDisable.js delete mode 100644 modules/worker/back/methods/workerDisableExclueded/checkExcluded.js diff --git a/modules/worker/back/methods/worker/workerDisableExcluded.js b/modules/worker/back/methods/worker/workerDisableExcluded.js new file mode 100644 index 000000000..017e044c2 --- /dev/null +++ b/modules/worker/back/methods/worker/workerDisableExcluded.js @@ -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; + }; +}; diff --git a/modules/worker/back/methods/worker/workerExcludeFromDisable.js b/modules/worker/back/methods/worker/workerExcludeFromDisable.js new file mode 100644 index 000000000..86d940862 --- /dev/null +++ b/modules/worker/back/methods/worker/workerExcludeFromDisable.js @@ -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; + }; +}; diff --git a/modules/worker/back/methods/workerDisableExclueded/checkExcluded.js b/modules/worker/back/methods/workerDisableExclueded/checkExcluded.js deleted file mode 100644 index 32260c01f..000000000 --- a/modules/worker/back/methods/workerDisableExclueded/checkExcluded.js +++ /dev/null @@ -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'; - }; -}; diff --git a/modules/worker/back/models/worker.js b/modules/worker/back/models/worker.js index ec6c4af28..c90729779 100644 --- a/modules/worker/back/models/worker.js +++ b/modules/worker/back/models/worker.js @@ -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); }; diff --git a/modules/worker/back/models/workerDisableExcluded.json b/modules/worker/back/models/workerDisableExcluded.json index eeffb4b15..cfa810e43 100644 --- a/modules/worker/back/models/workerDisableExcluded.json +++ b/modules/worker/back/models/workerDisableExcluded.json @@ -7,9 +7,12 @@ } }, "properties": { - "id": { + "workerFk": { "id": true, "type": "number" + }, + "dated": { + "type": "date" } }, "acls": [ diff --git a/modules/worker/front/descriptor/index.html b/modules/worker/front/descriptor/index.html index 0616f179f..d3caa78a8 100644 --- a/modules/worker/front/descriptor/index.html +++ b/modules/worker/front/descriptor/index.html @@ -15,14 +15,19 @@ - + + + Marcar para no deshabilitar + + + Marcar como deshabilitable +
diff --git a/modules/worker/front/descriptor/index.js b/modules/worker/front/descriptor/index.js index e1026382d..2f79c2d80 100644 --- a/modules/worker/front/descriptor/index.js +++ b/modules/worker/front/descriptor/index.js @@ -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() {