Merge pull request 'Added new filter param in item request' (!3094) from Fix-ItemRequest into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #3094
Reviewed-by: Javi Gallego <jgallego@verdnatura.es>
This commit is contained in:
Jon Elias 2024-10-21 09:34:53 +00:00
commit d75a032d75
1 changed files with 27 additions and 0 deletions

View File

@ -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}};
}
});