#7524 myteam filter #3134

Merged
jgallego merged 5 commits from 7524-hotfix-myTeamFilter into master 2024-10-22 11:59:45 +00:00
1 changed files with 26 additions and 0 deletions
Showing only changes of commit 288dc1c598 - Show all commits

View File

@ -50,6 +50,11 @@ module.exports = Self => {
type: 'boolean',
description: 'True when lines and stock of origin are equal'
},
{
arg: 'myTeam',
type: 'boolean',
description: `Whether to show only tickets for the current logged user team (currently user tickets)`
},
{
arg: 'filter',
type: 'object',
@ -69,11 +74,27 @@ module.exports = Self => {
Self.getTicketsAdvance = async(ctx, options) => {
const args = ctx.args;
const conn = Self.dataSource.connector;
const userId = ctx.req.accessToken.userId;
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
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 'id':
@ -96,6 +117,11 @@ module.exports = Self => {
};
case 'isFullMovable':
return {'f.isFullMovable': value};
case 'myTeam':
if (value)
return {'c.salesPersonFk': {inq: teamMembersId}};
else
return {'c.salesPersonFk': {nin: teamMembersId}};
}
});