Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 2283_e2e_delete_ticket_with_stowaway
This commit is contained in:
commit
538ae75b89
|
@ -100,34 +100,27 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.filter = async(ctx, filter) => {
|
Self.filter = async(ctx, filter) => {
|
||||||
|
const userId = ctx.req.accessToken.userId;
|
||||||
const conn = Self.dataSource.connector;
|
const conn = Self.dataSource.connector;
|
||||||
|
const models = Self.app.models;
|
||||||
const args = ctx.args;
|
const args = ctx.args;
|
||||||
|
|
||||||
let worker = await Self.app.models.Worker.findOne({
|
// Apply filter by team
|
||||||
where: {userFk: ctx.req.accessToken.userId},
|
const teamMembersId = [];
|
||||||
include: [
|
if (args.myTeam != null) {
|
||||||
{relation: 'collegues'}
|
const worker = await models.Worker.findById(userId, {
|
||||||
]
|
include: {
|
||||||
});
|
relation: 'collegues'
|
||||||
|
|
||||||
let teamIds = [];
|
|
||||||
|
|
||||||
if (worker.collegues().length && args.myTeam) {
|
|
||||||
worker.collegues().forEach(collegue => {
|
|
||||||
teamIds.push(collegue.collegueFk);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.mine || (worker.collegues().length === 0 && args.myTeam)) {
|
|
||||||
worker = await Self.app.models.Worker.findOne({
|
|
||||||
fields: ['id'],
|
|
||||||
where: {userFk: ctx.req.accessToken.userId}
|
|
||||||
});
|
});
|
||||||
teamIds = [worker && worker.id];
|
const collegues = worker.collegues() || [];
|
||||||
}
|
collegues.forEach(collegue => {
|
||||||
|
teamMembersId.push(collegue.collegueFk);
|
||||||
|
});
|
||||||
|
|
||||||
if (ctx.args && (args.mine || args.myTeam))
|
if (teamMembersId.length == 0)
|
||||||
args.teamIds = teamIds;
|
teamMembersId.push(userId);
|
||||||
|
}
|
||||||
|
|
||||||
if (ctx.args && args.to) {
|
if (ctx.args && args.to) {
|
||||||
const dateTo = args.to;
|
const dateTo = args.to;
|
||||||
|
@ -156,7 +149,11 @@ module.exports = Self => {
|
||||||
return {'ts.stateFk': value};
|
return {'ts.stateFk': value};
|
||||||
case 'mine':
|
case 'mine':
|
||||||
case 'myTeam':
|
case 'myTeam':
|
||||||
return {'c.salesPersonFk': {inq: teamIds}};
|
if (value)
|
||||||
|
return {'c.salesPersonFk': {inq: teamMembersId}};
|
||||||
|
else
|
||||||
|
return {'c.salesPersonFk': {nin: teamMembersId}};
|
||||||
|
|
||||||
case 'alertLevel':
|
case 'alertLevel':
|
||||||
return {'ts.alertLevel': value};
|
return {'ts.alertLevel': value};
|
||||||
case 'pending':
|
case 'pending':
|
||||||
|
|
|
@ -71,4 +71,20 @@ describe('ticket filter()', () => {
|
||||||
expect(secondRow.state).toEqual('Entregado');
|
expect(secondRow.state).toEqual('Entregado');
|
||||||
expect(thirdRow.state).toEqual('Entregado');
|
expect(thirdRow.state).toEqual('Entregado');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return the tickets from the worker team', async() => {
|
||||||
|
const ctx = {req: {accessToken: {userId: 9}}, args: {myTeam: true}};
|
||||||
|
const filter = {};
|
||||||
|
const result = await app.models.Ticket.filter(ctx, filter);
|
||||||
|
|
||||||
|
expect(result.length).toEqual(17);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the tickets that are not from the worker team', async() => {
|
||||||
|
const ctx = {req: {accessToken: {userId: 9}}, args: {myTeam: false}};
|
||||||
|
const filter = {};
|
||||||
|
const result = await app.models.Ticket.filter(ctx, filter);
|
||||||
|
|
||||||
|
expect(result.length).toEqual(7);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue