From 7b0dd6975d5dba526f1b08591902f8ffb646f8c0 Mon Sep 17 00:00:00 2001 From: pablone Date: Mon, 19 Feb 2024 14:13:36 +0100 Subject: [PATCH 1/2] fix(usesMana): refs #6879 add mana excluded worker --- .../back/methods/sale/specs/usesMana.spec.js | 31 +++++++++++++++---- modules/ticket/back/methods/sale/usesMana.js | 3 ++ modules/worker/back/model-config.json | 3 ++ .../back/models/worker-mana-excluded.json | 22 +++++++++++++ 4 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 modules/worker/back/models/worker-mana-excluded.json diff --git a/modules/ticket/back/methods/sale/specs/usesMana.spec.js b/modules/ticket/back/methods/sale/specs/usesMana.spec.js index 777bdc8f0..e82645d0b 100644 --- a/modules/ticket/back/methods/sale/specs/usesMana.spec.js +++ b/modules/ticket/back/methods/sale/specs/usesMana.spec.js @@ -1,11 +1,7 @@ const models = require('vn-loopback/server/server').models; -describe('sale usesMana()', () => { - const ctx = { - req: { - accessToken: {userId: 18} - } - }; +fdescribe('sale usesMana()', () => { + const ctx = {req: { accessToken: {userId: 18}}}; it('should return that the worker uses mana', async() => { const tx = await models.Sale.beginTransaction({}); @@ -45,4 +41,27 @@ describe('sale usesMana()', () => { throw e; } }); + + it('should return that the worker does not use mana because it is excluded', async() => { + const tx = await models.Sale.beginTransaction({}); + const buyerId = 35; + const franceDepartmentId = 133; + const buyerCtx = {req: {accessToken: {userId: buyerId}}}; + + try { + const options = {transaction: tx} + + await models.WorkerManaExcluded.create({workerFk: buyerId}, options); + await models.Business.updateAll({workerFk: buyerId}, {departmentFk: franceDepartmentId}, options); + + const usesMana = await models.Sale.usesMana(buyerCtx, options); + + expect(usesMana).toBe(false); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); }); diff --git a/modules/ticket/back/methods/sale/usesMana.js b/modules/ticket/back/methods/sale/usesMana.js index 75d8cdda7..31beb3a4c 100644 --- a/modules/ticket/back/methods/sale/usesMana.js +++ b/modules/ticket/back/methods/sale/usesMana.js @@ -21,6 +21,9 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); + const isManaExcluded = await models.WorkerManaExcluded.findById(userId, null, myOptions); + if (isManaExcluded) return false; + const salesDepartment = await models.Department.findOne({where: {code: 'VT'}, fields: 'id'}, myOptions); const departments = await models.Department.getLeaves(ctx, salesDepartment.id, null, myOptions); const workerDepartment = await models.WorkerDepartment.findById(userId, null, myOptions); diff --git a/modules/worker/back/model-config.json b/modules/worker/back/model-config.json index 8352eb070..e12ceada5 100644 --- a/modules/worker/back/model-config.json +++ b/modules/worker/back/model-config.json @@ -86,6 +86,9 @@ "WorkerMana": { "dataSource": "vn" }, + "WorkerManaExcluded": { + "dataSource": "vn" + }, "WorkerMistake": { "dataSource": "vn" }, diff --git a/modules/worker/back/models/worker-mana-excluded.json b/modules/worker/back/models/worker-mana-excluded.json new file mode 100644 index 000000000..6610b701b --- /dev/null +++ b/modules/worker/back/models/worker-mana-excluded.json @@ -0,0 +1,22 @@ +{ + "name": "WorkerManaExcluded", + "base": "VnModel", + "options": { + "mysql": { + "table": "workerManaExcluded" + } + }, + "properties": { + "workerFk": { + "id": true, + "type": "number" + } + }, + "relations": { + "worker": { + "type": "belongsTo", + "model": "Worker", + "foreignKey": "workerFk" + } + } +} From 011880eb728ea6029c59e60e5c71b0bce550775a Mon Sep 17 00:00:00 2001 From: pablone Date: Mon, 19 Feb 2024 14:15:44 +0100 Subject: [PATCH 2/2] fix(spec): refs #6879 remove f from describe --- modules/ticket/back/methods/sale/specs/usesMana.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/sale/specs/usesMana.spec.js b/modules/ticket/back/methods/sale/specs/usesMana.spec.js index e82645d0b..74465ab27 100644 --- a/modules/ticket/back/methods/sale/specs/usesMana.spec.js +++ b/modules/ticket/back/methods/sale/specs/usesMana.spec.js @@ -1,6 +1,6 @@ const models = require('vn-loopback/server/server').models; -fdescribe('sale usesMana()', () => { +describe('sale usesMana()', () => { const ctx = {req: { accessToken: {userId: 18}}}; it('should return that the worker uses mana', async() => {