refs #6641 addFilterCollegues
gitea/salix/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
jcasado 2024-04-04 14:28:39 +02:00
parent 5acef1fcc0
commit 1c6d913926
3 changed files with 51 additions and 5 deletions

View File

@ -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,6 +127,22 @@ module.exports = Self => {
claimIdsByClaimResponsibleFk = claims.map(claim => claim.claimFk);
}
// 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(args, (param, value) => {
switch (param) {
case 'search':
@ -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}};
}
});

View File

@ -97,4 +97,23 @@ describe('claim filter()', () => {
throw e;
}
});
it('should now return the tickets from the worker team', async() => {
const tx = await models.Claim.beginTransaction({});
try {
const options = {transaction: tx};
const ctx = {req: {accessToken: {userId: 18}}, args: {myTeam: true}};
const filter = {};
const result = await models.SalesMonitor.salesFilter(ctx, filter, options);
expect(result.length).toBeGreaterThan(20);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});

View File

@ -70,15 +70,15 @@
label="Responsible">
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal class="vn-mt-lg">
<vn-submit label="Search"></vn-submit>
</vn-horizontal>
<vn-horizontal class="vn-px-lg">
<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>
</form>
</div>