#7524 myteam filter #3134
|
@ -50,6 +50,11 @@ module.exports = Self => {
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
description: 'True when lines and stock of origin are equal'
|
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',
|
arg: 'filter',
|
||||||
type: 'object',
|
type: 'object',
|
||||||
|
@ -69,11 +74,27 @@ module.exports = Self => {
|
||||||
Self.getTicketsAdvance = async(ctx, options) => {
|
Self.getTicketsAdvance = async(ctx, options) => {
|
||||||
const args = ctx.args;
|
const args = ctx.args;
|
||||||
const conn = Self.dataSource.connector;
|
const conn = Self.dataSource.connector;
|
||||||
|
const userId = ctx.req.accessToken.userId;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
|
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
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) => {
|
const where = buildFilter(ctx.args, (param, value) => {
|
||||||
switch (param) {
|
switch (param) {
|
||||||
case 'id':
|
case 'id':
|
||||||
|
@ -96,6 +117,11 @@ module.exports = Self => {
|
||||||
};
|
};
|
||||||
case 'isFullMovable':
|
case 'isFullMovable':
|
||||||
return {'f.isFullMovable': value};
|
return {'f.isFullMovable': value};
|
||||||
|
case 'myTeam':
|
||||||
|
if (value)
|
||||||
|
return {'c.salesPersonFk': {inq: teamMembersId}};
|
||||||
|
else
|
||||||
|
return {'c.salesPersonFk': {nin: teamMembersId}};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue