7299_testToMaster #2411
|
@ -1827,9 +1827,9 @@ INSERT INTO `vn`.`claimState`(`id`, `code`, `description`, `roleFk`, `priority`,
|
|||
|
||||
INSERT INTO `vn`.`claim`(`id`, `ticketCreated`, `claimStateFk`, `clientFk`, `workerFk`, `responsibility`, `isChargedToMana`, `created`, `packages`, `ticketFk`)
|
||||
VALUES
|
||||
(1, util.VN_CURDATE(), 1, 1101, 18, 3, 0, util.VN_CURDATE(), 0, 11),
|
||||
(1, util.VN_CURDATE(), 1, 1101, 19, 3, 0, util.VN_CURDATE(), 0, 11),
|
||||
(2, util.VN_CURDATE(), 4, 1101, 18, 3, 0, util.VN_CURDATE(), 1, 16),
|
||||
(3, util.VN_CURDATE(), 3, 1101, 18, 1, 1, util.VN_CURDATE(), 5, 7),
|
||||
(3, util.VN_CURDATE(), 3, 1101, 19, 1, 1, util.VN_CURDATE(), 5, 7),
|
||||
(4, util.VN_CURDATE(), 3, 1104, 18, 5, 0, util.VN_CURDATE(), 10, 8);
|
||||
|
||||
INSERT INTO `vn`.`claimObservation` (`claimFk`, `workerFk`, `text`, `created`)
|
||||
|
@ -3761,3 +3761,8 @@ INSERT INTO `vn`.`accountReconciliation` (supplierAccountFk,operationDated,value
|
|||
|
||||
INSERT INTO `vn`.`accountReconciliationConfig`(currencyFk, warehouseFk)
|
||||
VALUES (1, 1);
|
||||
|
||||
|
||||
INSERT INTO vn.workerTeam(id, team, workerFk)
|
||||
VALUES
|
||||
(8, 1, 19);
|
||||
|
|
|
@ -79,7 +79,12 @@ module.exports = Self => {
|
|||
type: 'number',
|
||||
description: 'The claimResponsible id',
|
||||
http: {source: 'query'}
|
||||
}
|
||||
},
|
||||
{
|
||||
arg: 'myTeam',
|
||||
type: 'boolean',
|
||||
description: `Team partners`
|
||||
},
|
||||
],
|
||||
returns: {
|
||||
type: ['object'],
|
||||
|
@ -92,6 +97,7 @@ module.exports = Self => {
|
|||
});
|
||||
|
||||
Self.filter = async(ctx, filter, options) => {
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const models = Self.app.models;
|
||||
const conn = Self.dataSource.connector;
|
||||
const args = ctx.args;
|
||||
|
@ -121,7 +127,23 @@ module.exports = Self => {
|
|||
claimIdsByClaimResponsibleFk = claims.map(claim => claim.claimFk);
|
||||
}
|
||||
|
||||
const where = buildFilter(args, (param, value) => {
|
||||
// Apply filter by team
|
||||
const teamMembersId = [];
|
||||
if (args.myTeam != null) {
|
||||
const worker = await models.Worker.findById(userId, {
|
||||
include: {
|
||||
relation: 'collegues'
|
||||
}
|
||||
}, myOptions);
|
||||
const collegues = worker.collegues() || [];
|
||||
for (let collegue of collegues)
|
||||
teamMembersId.push(collegue.collegueFk);
|
||||
|
||||
if (teamMembersId.length == 0)
|
||||
teamMembersId.push(userId);
|
||||
}
|
||||
|
||||
const where = buildFilter(ctx.args, (param, value) => {
|
||||
switch (param) {
|
||||
case 'search':
|
||||
return /^\d+$/.test(value)
|
||||
|
@ -152,6 +174,11 @@ module.exports = Self => {
|
|||
to.setHours(23, 59, 59, 999);
|
||||
|
||||
return {'cl.created': {between: [value, to]}};
|
||||
case 'myTeam':
|
||||
if (value)
|
||||
return {'cl.workerFk': {inq: teamMembersId}};
|
||||
else
|
||||
return {'cl.workerFk': {nin: teamMembersId}};
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -1,13 +1,25 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
const models = require('vn-loopback/server/server').models;
|
||||
|
||||
describe('claim filter()', () => {
|
||||
let ctx;
|
||||
beforeEach(() => {
|
||||
ctx = {
|
||||
req: {
|
||||
accessToken: {userId: 9},
|
||||
headers: {origin: 'http://localhost'}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
it('should return 1 result filtering by id', async() => {
|
||||
const tx = await app.models.Claim.beginTransaction({});
|
||||
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
const result = await app.models.Claim.filter({args: {filter: {}, search: 1}}, null, options);
|
||||
ctx.args = {search: 1};
|
||||
const result = await app.models.Claim.filter(ctx, null, options);
|
||||
|
||||
expect(result.length).toEqual(1);
|
||||
expect(result[0].id).toEqual(1);
|
||||
|
@ -25,7 +37,8 @@ describe('claim filter()', () => {
|
|||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
const result = await app.models.Claim.filter({args: {filter: {}, search: 'Tony Stark'}}, null, options);
|
||||
ctx.args = {search: 'Tony Stark'};
|
||||
const result = await app.models.Claim.filter(ctx, null, options);
|
||||
|
||||
expect(result.length).toEqual(1);
|
||||
expect(result[0].id).toEqual(4);
|
||||
|
@ -43,7 +56,8 @@ describe('claim filter()', () => {
|
|||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
const result = await app.models.Claim.filter({args: {filter: {}, workerFk: 18}}, null, options);
|
||||
ctx.args = {workerFk: 18};
|
||||
const result = await app.models.Claim.filter(ctx, null, options);
|
||||
|
||||
expect(result.length).toEqual(4);
|
||||
expect(result[0].id).toEqual(1);
|
||||
|
@ -64,7 +78,8 @@ describe('claim filter()', () => {
|
|||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
const result = await app.models.Claim.filter({args: {filter: {}, itemFk: 2}}, null, options);
|
||||
ctx.args = {itemFk: 2};
|
||||
const result = await app.models.Claim.filter(ctx, null, options);
|
||||
|
||||
expect(result.length).toEqual(3);
|
||||
expect(result[0].id).toEqual(1);
|
||||
|
@ -84,7 +99,8 @@ describe('claim filter()', () => {
|
|||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
const result = await app.models.Claim.filter({args: {filter: {}, claimResponsibleFk: 7}}, null, options);
|
||||
ctx.args = {claimResponsibleFk: 7};
|
||||
const result = await app.models.Claim.filter(ctx, null, options);
|
||||
|
||||
expect(result.length).toEqual(3);
|
||||
expect(result[0].id).toEqual(2);
|
||||
|
@ -97,4 +113,22 @@ describe('claim filter()', () => {
|
|||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
it('should now return claims from the worker team', async() => {
|
||||
const tx = await models.Claim.beginTransaction({});
|
||||
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
ctx.args = {itemFk: null, myTeam: true};
|
||||
const result = await app.models.Claim.filter(ctx, null, options);
|
||||
|
||||
expect(result.length).toEqual(2);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -70,6 +70,13 @@
|
|||
label="Responsible">
|
||||
</vn-autocomplete>
|
||||
</vn-horizontal>
|
||||
<vn-horizontal>
|
||||
<vn-check
|
||||
vn-one
|
||||
label="My team"
|
||||
ng-model="filter.myTeam"
|
||||
triple-state="true">
|
||||
</vn-horizontal>
|
||||
<vn-horizontal class="vn-mt-lg">
|
||||
<vn-submit label="Search"></vn-submit>
|
||||
</vn-horizontal>
|
||||
|
|
Loading…
Reference in New Issue