8179-testToMaster #3176
|
@ -59,6 +59,11 @@ module.exports = Self => {
|
|||
arg: 'state',
|
||||
type: 'string',
|
||||
description: `Search request by request state`
|
||||
},
|
||||
{
|
||||
arg: 'myTeam',
|
||||
type: 'boolean',
|
||||
description: `Team partners`
|
||||
}
|
||||
],
|
||||
returns: {
|
||||
|
@ -75,6 +80,8 @@ module.exports = Self => {
|
|||
const conn = Self.dataSource.connector;
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const myOptions = {};
|
||||
const models = Self.app.models;
|
||||
const args = ctx.args;
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
@ -82,6 +89,21 @@ module.exports = Self => {
|
|||
if (ctx.args.mine)
|
||||
ctx.args.attenderFk = userId;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
let where = buildFilter(ctx.args, (param, value) => {
|
||||
switch (param) {
|
||||
case 'search':
|
||||
|
@ -113,6 +135,11 @@ module.exports = Self => {
|
|||
return {'w.id': value};
|
||||
case 'salesPersonFk':
|
||||
return {'c.salesPersonFk': value};
|
||||
case 'myTeam':
|
||||
if (value)
|
||||
return {'tr.requesterFk': {inq: teamMembersId}};
|
||||
else
|
||||
return {'tr.requesterFk': {nin: teamMembersId}};
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue