Added new filter param in item request #3094

Merged
jon merged 6 commits from Fix-ItemRequest into dev 2024-10-21 09:34:54 +00:00
1 changed files with 28 additions and 0 deletions
Showing only changes of commit 4ee6a46bd5 - Show all commits

View File

@ -59,6 +59,11 @@ module.exports = Self => {
arg: 'state', arg: 'state',
type: 'string', type: 'string',
description: `Search request by request state` description: `Search request by request state`
},
{
arg: 'myTeam',
type: 'boolean',
description: `Team partners`
} }
], ],
returns: { returns: {
@ -75,6 +80,24 @@ module.exports = Self => {
const conn = Self.dataSource.connector; const conn = Self.dataSource.connector;
const userId = ctx.req.accessToken.userId; const userId = ctx.req.accessToken.userId;
const myOptions = {}; const myOptions = {};
const models = Self.app.models;
const args = ctx.args;
// Apply filter by team
jgallego marked this conversation as resolved Outdated

subimos el codigo sin comentarios..

Esta hecho igual que las otras secciones que buscan departamentos?

subimos el codigo sin comentarios.. Esta hecho igual que las otras secciones que buscan departamentos?
Outdated
Review

Me he guiado de como está hecho en claim/filter.
De todas formas pongo a @alexm para que le pegue un vistazo por si me he dejado algo.

Me he guiado de como está hecho en claim/filter. De todas formas pongo a @alexm para que le pegue un vistazo por si me he dejado algo.
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);
}
if (typeof options == 'object') if (typeof options == 'object')
Object.assign(myOptions, options); Object.assign(myOptions, options);
@ -113,6 +136,11 @@ module.exports = Self => {
return {'w.id': value}; return {'w.id': value};
case 'salesPersonFk': case 'salesPersonFk':
return {'c.salesPersonFk': value}; return {'c.salesPersonFk': value};
case 'myTeam':
if (value)
return {'c.salesPersonFk': {inq: teamMembersId}};
else
return {'c.salesPersonFk': {nin: teamMembersId}};
} }
}); });