This commit is contained in:
Carlos Jimenez Ruiz 2019-07-03 14:40:53 +02:00
commit fc80848506
4 changed files with 3382 additions and 5652 deletions

View File

@ -47,6 +47,10 @@ module.exports = Self => {
arg: 'workerFk', arg: 'workerFk',
type: 'Integer', type: 'Integer',
description: `The salesperson id` 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', arg: 'isConfirmed',
type: 'Boolean', type: 'Boolean',
@ -65,7 +69,30 @@ module.exports = Self => {
Self.filter = async(ctx, filter) => { Self.filter = async(ctx, filter) => {
let conn = Self.dataSource.connector; 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) => { let where = buildFilter(ctx.args, (param, value) => {
switch (param) { switch (param) {
case 'search': case 'search':
@ -86,6 +113,8 @@ module.exports = Self => {
return {'ort.ticketFk': value}; return {'ort.ticketFk': value};
case 'isConfirmed': case 'isConfirmed':
return {'o.confirmed': value ? 1 : 0}; return {'o.confirmed': value ? 1 : 0};
case 'myTeam':
return {'c.salesPersonFk': {inq: teamIds}};
case 'id': case 'id':
param = `o.${param}`; param = `o.${param}`;
return {[param]: value}; return {[param]: value};

View File

@ -1,9 +1,13 @@
const app = require('vn-loopback/server/server'); const app = require('vn-loopback/server/server');
describe('order filter()', () => { describe('order filter()', () => {
it('should call the filter method with a basic search', async() => { let ctx = {
let ctx = {params: {}}; req: {accessToken: {userId: 9}},
args: {},
params: {}
};
it('should call the filter method with a basic search', async() => {
let filter = {where: {'o.id': 2}}; let filter = {where: {'o.id': 2}};
let result = await app.models.Order.filter(ctx, filter); let result = await app.models.Order.filter(ctx, filter);
let orderId = result[0].id; let orderId = result[0].id;
@ -12,8 +16,6 @@ describe('order filter()', () => {
}); });
it('should call the filter method with a single advanced search', async() => { it('should call the filter method with a single advanced search', async() => {
let ctx = {params: {}};
let filter = {where: {'o.confirmed': false}}; let filter = {where: {'o.confirmed': false}};
let result = await app.models.Order.filter(ctx, filter); 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() => { 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 filter = {where: {'o.confirmed': false, 'c.salesPersonFk': 19}};
let result = await app.models.Order.filter(ctx, filter); let result = await app.models.Order.filter(ctx, filter);

View File

@ -57,8 +57,6 @@
label="Ticket id" label="Ticket id"
model="filter.ticketFk"> model="filter.ticketFk">
</vn-textfield> </vn-textfield>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete <vn-autocomplete
vn-one vn-one
label="Application" label="Application"
@ -67,6 +65,14 @@
show-field="value" show-field="value"
value-field="value"> value-field="value">
</vn-autocomplete> </vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-check
vn-one
label="My team"
field="filter.myTeam"
triple-state="true">
</vn-check>
<vn-check <vn-check
vn-one vn-one
label="Order confirmed" label="Order confirmed"

8967
package-lock.json generated

File diff suppressed because it is too large Load Diff