merge
This commit is contained in:
commit
fc80848506
|
@ -47,6 +47,10 @@ module.exports = Self => {
|
|||
arg: 'workerFk',
|
||||
type: 'Integer',
|
||||
description: `The salesperson id`
|
||||
}, {
|
||||
arg: 'myTeam',
|
||||
type: 'Boolean',
|
||||
description: `Whether to show only tickets for the current logged user team (For now it shows only the current user tickets)`
|
||||
}, {
|
||||
arg: 'isConfirmed',
|
||||
type: 'Boolean',
|
||||
|
@ -65,7 +69,30 @@ module.exports = Self => {
|
|||
|
||||
Self.filter = async(ctx, filter) => {
|
||||
let conn = Self.dataSource.connector;
|
||||
let worker = await Self.app.models.Worker.findOne({
|
||||
where: {userFk: ctx.req.accessToken.userId},
|
||||
include: [
|
||||
{relation: 'collegues'}
|
||||
]
|
||||
});
|
||||
let teamIds = [];
|
||||
|
||||
if (worker.collegues().length && ctx.args.myTeam) {
|
||||
worker.collegues().forEach(collegue => {
|
||||
teamIds.push(collegue.collegueFk);
|
||||
});
|
||||
}
|
||||
|
||||
if (worker.collegues().length === 0 && ctx.args.myTeam) {
|
||||
worker = await Self.app.models.Worker.findOne({
|
||||
fields: ['id'],
|
||||
where: {userFk: ctx.req.accessToken.userId}
|
||||
});
|
||||
teamIds = [worker && worker.id];
|
||||
}
|
||||
|
||||
if (ctx.args && ctx.args.myTeam)
|
||||
ctx.args.teamIds = teamIds;
|
||||
let where = buildFilter(ctx.args, (param, value) => {
|
||||
switch (param) {
|
||||
case 'search':
|
||||
|
@ -86,6 +113,8 @@ module.exports = Self => {
|
|||
return {'ort.ticketFk': value};
|
||||
case 'isConfirmed':
|
||||
return {'o.confirmed': value ? 1 : 0};
|
||||
case 'myTeam':
|
||||
return {'c.salesPersonFk': {inq: teamIds}};
|
||||
case 'id':
|
||||
param = `o.${param}`;
|
||||
return {[param]: value};
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
|
||||
describe('order filter()', () => {
|
||||
it('should call the filter method with a basic search', async() => {
|
||||
let ctx = {params: {}};
|
||||
let ctx = {
|
||||
req: {accessToken: {userId: 9}},
|
||||
args: {},
|
||||
params: {}
|
||||
};
|
||||
|
||||
it('should call the filter method with a basic search', async() => {
|
||||
let filter = {where: {'o.id': 2}};
|
||||
let result = await app.models.Order.filter(ctx, filter);
|
||||
let orderId = result[0].id;
|
||||
|
@ -12,8 +16,6 @@ describe('order filter()', () => {
|
|||
});
|
||||
|
||||
it('should call the filter method with a single advanced search', async() => {
|
||||
let ctx = {params: {}};
|
||||
|
||||
let filter = {where: {'o.confirmed': false}};
|
||||
let result = await app.models.Order.filter(ctx, filter);
|
||||
|
||||
|
@ -21,8 +23,6 @@ describe('order filter()', () => {
|
|||
});
|
||||
|
||||
it('should call the filter method with a complex advanced search', async() => {
|
||||
let ctx = {params: {}};
|
||||
|
||||
let filter = {where: {'o.confirmed': false, 'c.salesPersonFk': 19}};
|
||||
let result = await app.models.Order.filter(ctx, filter);
|
||||
|
||||
|
|
|
@ -57,8 +57,6 @@
|
|||
label="Ticket id"
|
||||
model="filter.ticketFk">
|
||||
</vn-textfield>
|
||||
</vn-horizontal>
|
||||
<vn-horizontal>
|
||||
<vn-autocomplete
|
||||
vn-one
|
||||
label="Application"
|
||||
|
@ -67,6 +65,14 @@
|
|||
show-field="value"
|
||||
value-field="value">
|
||||
</vn-autocomplete>
|
||||
</vn-horizontal>
|
||||
<vn-horizontal>
|
||||
<vn-check
|
||||
vn-one
|
||||
label="My team"
|
||||
field="filter.myTeam"
|
||||
triple-state="true">
|
||||
</vn-check>
|
||||
<vn-check
|
||||
vn-one
|
||||
label="Order confirmed"
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue