Merge pull request 'fix(usesMana): refs #6879 add mana excluded worker' (!2053) from 6879-fixUsesManaExlusion into master
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #2053 Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
commit
f731fbe01c
|
@ -1,11 +1,7 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
|
||||
describe('sale usesMana()', () => {
|
||||
const ctx = {
|
||||
req: {
|
||||
accessToken: {userId: 18}
|
||||
}
|
||||
};
|
||||
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;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -86,6 +86,9 @@
|
|||
"WorkerMana": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"WorkerManaExcluded": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"WorkerMistake": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue