#7524 myteam filter #3134
|
@ -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}};
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue