This commit is contained in:
parent
3a6df984aa
commit
d6637a32ce
|
@ -72,7 +72,7 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
filter = mergeFilters(ctx.args.filter, {where});
|
filter = mergeFilters(ctx.args?.filter ?? {}, {where});
|
||||||
|
|
||||||
const supplier = await Self.app.models.Supplier.isSupplier(ctx, myOptions);
|
const supplier = await Self.app.models.Supplier.isSupplier(ctx, myOptions);
|
||||||
if (supplier) {
|
if (supplier) {
|
||||||
|
|
|
@ -1,88 +1,62 @@
|
||||||
const app = require('vn-loopback/server/server');
|
|
||||||
const models = require('vn-loopback/server/server').models;
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
fdescribe('AgencyTerm filter()', () => {
|
describe('AgencyTerm filter()', () => {
|
||||||
const authUserId = 9;
|
const ctx = beforeAll.getCtx();
|
||||||
const today = Date.vnNew();
|
|
||||||
today.setHours(2, 0, 0, 0);
|
|
||||||
let tx;
|
|
||||||
let ctx = beforeAll.getCtx();
|
|
||||||
console.log('ctx', ctx);
|
|
||||||
it('should return all results matching the filter', async() => {
|
it('should return all results matching the filter', async() => {
|
||||||
tx = await models.AgencyTerm.beginTransaction({});
|
ctx.args = {};
|
||||||
|
const agencyTerms = await models.AgencyTerm.filter(ctx);
|
||||||
try {
|
|
||||||
const options = {transaction: tx};
|
|
||||||
const filter = {};
|
|
||||||
ctx = {req: {accessToken: {userId: authUserId}}};
|
|
||||||
|
|
||||||
const agencyTerms = await models.AgencyTerm.filter(ctx, filter, options);
|
|
||||||
const firstAgencyTerm = agencyTerms[0];
|
const firstAgencyTerm = agencyTerms[0];
|
||||||
|
|
||||||
expect(firstAgencyTerm.routeFk).toEqual(1);
|
expect(firstAgencyTerm.routeFk).toEqual(1);
|
||||||
expect(agencyTerms.length).toEqual(5);
|
expect(agencyTerms.length).toEqual(5);
|
||||||
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return results matching "search" searching by integer', async() => {
|
it('should return results matching "search" searching by integer', async() => {
|
||||||
const ctx = {req: {args: {search: 1}}};
|
const search = 1;
|
||||||
|
ctx.args = {search};
|
||||||
|
|
||||||
let result = await app.models.AgencyTerm.filter(ctx);
|
const [result] = await models.AgencyTerm.filter(ctx);
|
||||||
|
|
||||||
expect(result.length).toEqual(1);
|
expect(result.invoiceInFk).toEqual(search);
|
||||||
expect(result[0].routeFk).toEqual(1);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return results matching "search" searching by string', async() => {
|
it('should return results matching "search" searching by string', async() => {
|
||||||
const ctx = {req: {args: {search: 'Plants SL'}}};
|
ctx.args = {search: 'Plants SL'};
|
||||||
let result = await app.models.AgencyTerm.filter(ctx);
|
|
||||||
|
let result = await models.AgencyTerm.filter(ctx);
|
||||||
|
|
||||||
expect(result.length).toEqual(2);
|
expect(result.length).toEqual(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return results matching "from" and "to"', async() => {
|
it('should return results matching "from" and "to"', async() => {
|
||||||
tx = await models.Buy.beginTransaction({});
|
|
||||||
const options = {transaction: tx};
|
|
||||||
|
|
||||||
try {
|
|
||||||
const from = Date.vnNew();
|
const from = Date.vnNew();
|
||||||
from.setHours(0, 0, 0, 0);
|
from.setHours(0, 0, 0, 0);
|
||||||
|
|
||||||
const to = Date.vnNew();
|
const to = Date.vnNew();
|
||||||
to.setHours(23, 59, 59, 999);
|
to.setHours(23, 59, 59, 999);
|
||||||
|
|
||||||
const ctx = {req: {args: {from: from, to: to}}};
|
ctx.args = {from, to};
|
||||||
|
|
||||||
const results = await models.AgencyTerm.filter(ctx, options);
|
const results = await models.AgencyTerm.filter(ctx);
|
||||||
|
|
||||||
expect(results.length).toBe(5);
|
expect(results.length).toBe(5);
|
||||||
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return results matching "agencyModeFk"', async() => {
|
it('should return results matching "agencyModeFk"', async() => {
|
||||||
const ctx = {req: {args: {agencyModeFk: 1}}};
|
const agencyModeFk = 1;
|
||||||
|
ctx.args = {agencyModeFk};
|
||||||
|
|
||||||
let result = await app.models.AgencyTerm.filter(ctx);
|
const [result] = await models.AgencyTerm.filter(ctx);
|
||||||
|
|
||||||
expect(result.length).toEqual(1);
|
expect(result.agencyModeFk).toEqual(agencyModeFk);
|
||||||
expect(result[0].routeFk).toEqual(1);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return results matching "agencyFk"', async() => {
|
it('should return results matching "agencyFk"', async() => {
|
||||||
const ctx = {req: {args: {agencyFk: 1}}};
|
const agencyFk = 1;
|
||||||
let result = await app.models.AgencyTerm.filter(ctx);
|
ctx.args = {agencyFk};
|
||||||
|
const [result] = await models.AgencyTerm.filter(ctx);
|
||||||
|
|
||||||
expect(result.length).toEqual(1);
|
expect(result.agencyFk).toEqual(agencyFk);
|
||||||
expect(result[0].routeFk).toEqual(2);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,109 +1,109 @@
|
||||||
const app = require('vn-loopback/server/server');
|
// const app = require('vn-loopback/server/server');
|
||||||
const models = require('vn-loopback/server/server').models;
|
// const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
describe('AgencyTerm filter()', () => {
|
// describe('Clone ', () => {
|
||||||
const authUserId = 9;
|
// const authUserId = 9;
|
||||||
const today = Date.vnNew();
|
// const today = Date.vnNew();
|
||||||
today.setHours(2, 0, 0, 0);
|
// today.setHours(2, 0, 0, 0);
|
||||||
|
|
||||||
it('should return all results matching the filter', async() => {
|
// it('should return all results matching the filter', async() => {
|
||||||
const tx = await models.AgencyTerm.beginTransaction({});
|
// const tx = await models.AgencyTerm.beginTransaction({});
|
||||||
|
|
||||||
try {
|
// try {
|
||||||
const options = {transaction: tx};
|
// const options = {transaction: tx};
|
||||||
const filter = {};
|
// const filter = {};
|
||||||
const ctx = {req: {accessToken: {userId: authUserId}}};
|
// const ctx = {req: {accessToken: {userId: authUserId}}};
|
||||||
|
|
||||||
const agencyTerms = await models.AgencyTerm.filter(ctx, filter, options);
|
// const agencyTerms = await models.AgencyTerm.filter(ctx, filter, options);
|
||||||
const firstAgencyTerm = agencyTerms[0];
|
// const firstAgencyTerm = agencyTerms[0];
|
||||||
|
|
||||||
expect(firstAgencyTerm.routeFk).toEqual(1);
|
// expect(firstAgencyTerm.routeFk).toEqual(1);
|
||||||
expect(agencyTerms.length).toEqual(5);
|
// expect(agencyTerms.length).toEqual(5);
|
||||||
|
|
||||||
await tx.rollback();
|
// await tx.rollback();
|
||||||
} catch (e) {
|
// } catch (e) {
|
||||||
await tx.rollback();
|
// await tx.rollback();
|
||||||
throw e;
|
// throw e;
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
|
||||||
it('should return results matching "search" searching by integer', async() => {
|
// it('should return results matching "search" searching by integer', async() => {
|
||||||
let ctx = {
|
// let ctx = {
|
||||||
args: {
|
// args: {
|
||||||
search: 1,
|
// search: 1,
|
||||||
}
|
// }
|
||||||
};
|
// };
|
||||||
|
|
||||||
let result = await app.models.AgencyTerm.filter(ctx);
|
// let result = await app.models.AgencyTerm.filter(ctx);
|
||||||
|
|
||||||
expect(result.length).toEqual(1);
|
// expect(result.length).toEqual(1);
|
||||||
expect(result[0].routeFk).toEqual(1);
|
// expect(result[0].routeFk).toEqual(1);
|
||||||
});
|
// });
|
||||||
|
|
||||||
it('should return results matching "search" searching by string', async() => {
|
// it('should return results matching "search" searching by string', async() => {
|
||||||
let ctx = {
|
// let ctx = {
|
||||||
args: {
|
// args: {
|
||||||
search: 'Plants SL',
|
// search: 'Plants SL',
|
||||||
}
|
// }
|
||||||
};
|
// };
|
||||||
|
|
||||||
let result = await app.models.AgencyTerm.filter(ctx);
|
// let result = await app.models.AgencyTerm.filter(ctx);
|
||||||
|
|
||||||
expect(result.length).toEqual(2);
|
// expect(result.length).toEqual(2);
|
||||||
});
|
// });
|
||||||
|
|
||||||
it('should return results matching "from" and "to"', async() => {
|
// it('should return results matching "from" and "to"', async() => {
|
||||||
const tx = await models.Buy.beginTransaction({});
|
// const tx = await models.Buy.beginTransaction({});
|
||||||
const options = {transaction: tx};
|
// const options = {transaction: tx};
|
||||||
|
|
||||||
try {
|
// try {
|
||||||
const from = Date.vnNew();
|
// const from = Date.vnNew();
|
||||||
from.setHours(0, 0, 0, 0);
|
// from.setHours(0, 0, 0, 0);
|
||||||
|
|
||||||
const to = Date.vnNew();
|
// const to = Date.vnNew();
|
||||||
to.setHours(23, 59, 59, 999);
|
// to.setHours(23, 59, 59, 999);
|
||||||
|
|
||||||
const ctx = {
|
// const ctx = {
|
||||||
args: {
|
// args: {
|
||||||
from: from,
|
// from: from,
|
||||||
to: to
|
// to: to
|
||||||
}
|
// }
|
||||||
};
|
// };
|
||||||
|
|
||||||
const results = await models.AgencyTerm.filter(ctx, options);
|
// const results = await models.AgencyTerm.filter(ctx, options);
|
||||||
|
|
||||||
expect(results.length).toBe(5);
|
// expect(results.length).toBe(5);
|
||||||
|
|
||||||
await tx.rollback();
|
// await tx.rollback();
|
||||||
} catch (e) {
|
// } catch (e) {
|
||||||
await tx.rollback();
|
// await tx.rollback();
|
||||||
throw e;
|
// throw e;
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
|
||||||
it('should return results matching "agencyModeFk"', async() => {
|
// it('should return results matching "agencyModeFk"', async() => {
|
||||||
let ctx = {
|
// let ctx = {
|
||||||
args: {
|
// args: {
|
||||||
agencyModeFk: 1,
|
// agencyModeFk: 1,
|
||||||
}
|
// }
|
||||||
};
|
// };
|
||||||
|
|
||||||
let result = await app.models.AgencyTerm.filter(ctx);
|
// let result = await app.models.AgencyTerm.filter(ctx);
|
||||||
|
|
||||||
expect(result.length).toEqual(1);
|
// expect(result.length).toEqual(1);
|
||||||
expect(result[0].routeFk).toEqual(1);
|
// expect(result[0].routeFk).toEqual(1);
|
||||||
});
|
// });
|
||||||
|
|
||||||
it('should return results matching "agencyFk"', async() => {
|
// it('should return results matching "agencyFk"', async() => {
|
||||||
let ctx = {
|
// let ctx = {
|
||||||
args: {
|
// args: {
|
||||||
agencyFk: 2,
|
// agencyFk: 2,
|
||||||
}
|
// }
|
||||||
};
|
// };
|
||||||
|
|
||||||
let result = await app.models.AgencyTerm.filter(ctx);
|
// let result = await app.models.AgencyTerm.filter(ctx);
|
||||||
|
|
||||||
expect(result.length).toEqual(1);
|
// expect(result.length).toEqual(1);
|
||||||
expect(result[0].routeFk).toEqual(2);
|
// expect(result[0].routeFk).toEqual(2);
|
||||||
});
|
// });
|
||||||
});
|
// });
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const app = require('vn-loopback/server/server');
|
||||||
|
|
||||||
describe('route getTickets()', () => {
|
describe('route getTickets()', () => {
|
||||||
|
const ctx = beforeAll.getCtx();
|
||||||
|
|
||||||
it('should return the tickets for a given route', async() => {
|
it('should return the tickets for a given route', async() => {
|
||||||
const filter = {id: 2};
|
const filter = {id: 2};
|
||||||
let result = await app.models.Route.getTickets(ctx, filter);
|
let result = await app.models.Route.getTickets(ctx, filter);
|
||||||
|
|
|
@ -1,51 +1,38 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const app = require('vn-loopback/server/server');
|
||||||
|
|
||||||
describe('route summary()', () => {
|
describe('route summary()', () => {
|
||||||
let ctx = beforeAll.getCtx();
|
const id = 1;
|
||||||
beforeAll(async() => {
|
const ctx = beforeAll.getCtx();
|
||||||
ctx = {
|
|
||||||
req: {
|
|
||||||
accessToken: {},
|
|
||||||
headers: {origin: 'http://localhost'},
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return a summary object containing data from one route', async() => {
|
it('should return a summary object containing data from one route', async() => {
|
||||||
const filter = {
|
const result = await app.models.Route.summary(ctx, id);
|
||||||
id: 1
|
|
||||||
};
|
|
||||||
const result = await app.models.Route.summary(ctx, filter);
|
|
||||||
|
|
||||||
expect(result.route.id).toEqual(1);
|
expect(result.route.id).toEqual(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should return a summary object containing it's agency`, async() => {
|
it(`should return a summary object containing it's agency`, async() => {
|
||||||
const filter = {
|
const result = await app.models.Route.summary(ctx, id);
|
||||||
id: 1
|
|
||||||
};
|
|
||||||
const result = await app.models.Route.summary(ctx, filter);
|
|
||||||
const agency = result.route.agencyMode();
|
const agency = result.route.agencyMode();
|
||||||
|
|
||||||
expect(agency.name).toEqual('inhouse pickup');
|
expect(agency.name).toEqual('inhouse pickup');
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should return a summary object containing it's vehicle`, async() => {
|
it(`should return a summary object containing it's vehicle`, async() => {
|
||||||
const result = await app.models.Route.summary(ctx, filter);
|
const result = await app.models.Route.summary(ctx, id);
|
||||||
const vehicle = result.route.vehicle();
|
const vehicle = result.route.vehicle();
|
||||||
|
|
||||||
expect(vehicle.numberPlate).toEqual('3333-BAT');
|
expect(vehicle.numberPlate).toEqual('3333-BAT');
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should return a summary object containing it's worker`, async() => {
|
it(`should return a summary object containing it's worker`, async() => {
|
||||||
const result = await app.models.Route.summary(ctx, filter);
|
const result = await app.models.Route.summary(ctx, id);
|
||||||
const worker = result.route.worker().user();
|
const worker = result.route.worker().user();
|
||||||
|
|
||||||
expect(worker.name).toEqual('delivery');
|
expect(worker.name).toEqual('delivery');
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should return a summary object containing data from the tickets`, async() => {
|
it(`should return a summary object containing data from the tickets`, async() => {
|
||||||
const result = await app.models.Route.summary(ctx, filter);
|
const result = await app.models.Route.summary(ctx, 2);
|
||||||
|
|
||||||
expect(result.tickets.length).toEqual(1);
|
expect(result.tickets.length).toEqual(1);
|
||||||
});
|
});
|
||||||
|
|
|
@ -164,10 +164,15 @@ module.exports = Self => {
|
||||||
throw new UserError('The social name has an invalid format');
|
throw new UserError('The social name has an invalid format');
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.isSupplier = async(ctx, options = {}) => {
|
Self.isSupplier = async(ctx, options) => {
|
||||||
|
const myOptions = {};
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
const userId = ctx.req.accessToken.userId;
|
const userId = ctx.req.accessToken.userId;
|
||||||
const client = await Self.app.models.Client.findById(userId, options);
|
const client = await Self.app.models.Client.findById(userId, null, myOptions);
|
||||||
const supplier = await Self.app.models.Supplier.findOne({where: {nif: client.fi}}, options);
|
const supplier = await Self.app.models.Supplier.findOne({where: {nif: client.fi}}, myOptions);
|
||||||
return supplier;
|
return supplier;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue