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) => {
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const conn = Self.dataSource.connector;
|
||||
const models = Self.app.models;
|
||||
const args = ctx.args;
|
||||
|
||||
let worker = await Self.app.models.Worker.findOne({
|
||||
where: {userFk: ctx.req.accessToken.userId},
|
||||
include: [
|
||||
{relation: 'collegues'}
|
||||
]
|
||||
});
|
||||
|
||||
let teamIds = [];
|
||||
|
||||
if (worker.collegues().length && args.myTeam) {
|
||||
worker.collegues().forEach(collegue => {
|
||||
teamIds.push(collegue.collegueFk);
|
||||
// Apply filter by team
|
||||
const teamMembersId = [];
|
||||
if (args.myTeam != null) {
|
||||
const worker = await models.Worker.findById(userId, {
|
||||
include: {
|
||||
relation: 'collegues'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (args.mine || (worker.collegues().length === 0 && args.myTeam)) {
|
||||
worker = await Self.app.models.Worker.findOne({
|
||||
fields: ['id'],
|
||||
where: {userFk: ctx.req.accessToken.userId}
|
||||
const collegues = worker.collegues() || [];
|
||||
collegues.forEach(collegue => {
|
||||
teamMembersId.push(collegue.collegueFk);
|
||||
});
|
||||
teamIds = [worker && worker.id];
|
||||
}
|
||||
|
||||
if (ctx.args && (args.mine || args.myTeam))
|
||||
args.teamIds = teamIds;
|
||||
if (teamMembersId.length == 0)
|
||||
teamMembersId.push(userId);
|
||||
}
|
||||
|
||||
if (ctx.args && args.to) {
|
||||
const dateTo = args.to;
|
||||
|
@ -156,7 +149,11 @@ module.exports = Self => {
|
|||
return {'ts.stateFk': value};
|
||||
case 'mine':
|
||||
case 'myTeam':
|
||||
return {'c.salesPersonFk': {inq: teamIds}};
|
||||
if (value)
|
||||
return {'c.salesPersonFk': {inq: teamMembersId}};
|
||||
else
|
||||
return {'c.salesPersonFk': {nin: teamMembersId}};
|
||||
|
||||
case 'alertLevel':
|
||||
return {'ts.alertLevel': value};
|
||||
case 'pending':
|
||||
|
|
|
@ -71,4 +71,20 @@ describe('ticket filter()', () => {
|
|||
expect(secondRow.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