filter worker id refactor
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
5a448234d6
commit
d83995e64e
|
@ -21,7 +21,7 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
Self.removes = async params => {
|
||||
Self.removes = async(params, options) => {
|
||||
const myOptions = {};
|
||||
let tx;
|
||||
|
||||
|
|
|
@ -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':
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue