filter worker id refactor
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Carlos Jimenez Ruiz 2021-12-17 10:41:59 +01:00
parent 5a448234d6
commit d83995e64e
3 changed files with 18 additions and 21 deletions

View File

@ -21,7 +21,7 @@ module.exports = Self => {
}
});
Self.removes = async params => {
Self.removes = async(params, options) => {
const myOptions = {};
let tx;

View File

@ -78,29 +78,22 @@ module.exports = Self => {
if (typeof options == 'object')
Object.assign(myOptions, options);
let worker = await Self.app.models.Worker.findOne({
where: {userFk: ctx.req.accessToken.userId},
include: [
{relation: 'collegues'}
]
}, myOptions);
const args = ctx.args;
let teamIds = [];
if (worker.collegues().length && args.myTeam) {
worker.collegues().forEach(collegue => {
teamIds.push(collegue.collegueFk);
});
}
if (worker.collegues().length === 0 && args.myTeam) {
worker = await Self.app.models.Worker.findOne({
fields: ['id'],
where: {userFk: ctx.req.accessToken.userId}
// Apply filter by team
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);
teamIds = [worker && worker.id];
if (teamMembersId.length == 0)
teamMembersId.push(userId);
}
if (args && args.myTeam)
@ -131,7 +124,10 @@ module.exports = Self => {
case 'isConfirmed':
return {'o.confirmed': value ? 1 : 0};
case 'myTeam':
return {'c.salesPersonFk': {inq: teamIds}};
if (value)
return {'c.salesPersonFk': {inq: teamMembersId}};
else
return {'c.salesPersonFk': {nin: teamMembersId}};
case 'showEmpty':
return {'o.total': {neq: value}};
case 'id':

View File

@ -43,6 +43,7 @@ module.exports = Self => {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
try {
const order = await models.Order.findById(id, null, myOptions);
const orderRows = await models.OrderRow.find({where: {orderFk: id}}, myOptions);