feat: add backTest
gitea/salix/pipeline/head This commit is unstable
Details
gitea/salix/pipeline/head This commit is unstable
Details
This commit is contained in:
parent
aab484ad41
commit
a9badfc1ba
|
@ -1,2 +1,4 @@
|
|||
INSERT INTO `salix`.`ACL`(`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
|
||||
VALUES('ZoneExclusionGeo', '*', '*', 'ALLOW', 'ROLE', 'employee');
|
||||
VALUES
|
||||
('ZoneExclusionGeo', '*', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||
('ZoneExclusionGeo', '*', 'WRITE', 'ALLOW', 'ROLE', 'deliveryBoss');
|
|
@ -224,5 +224,6 @@
|
|||
"The agency is already assigned to another autonomous": "La agencia ya está asignada a otro autónomo",
|
||||
"date in the future": "Fecha en el futuro",
|
||||
"reference duplicated": "Referencia duplicada",
|
||||
"This ticket is already a refund": "Este ticket ya es un abono"
|
||||
"This ticket is already a refund": "Este ticket ya es un abono",
|
||||
"You must select a location": "Debes seleccionar una localización"
|
||||
}
|
|
@ -1,7 +1,9 @@
|
|||
|
||||
const UserError = require('vn-loopback/util/user-error');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethod('exclusionGeo', {
|
||||
description: 'Exclude a zoneGeo for a zone',
|
||||
description: 'Exclude a zoneGeo from a zone',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'zoneFk',
|
||||
|
@ -30,19 +32,33 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
Self.exclusionGeo = async(zoneFk, date, geoIds) => {
|
||||
Self.exclusionGeo = async(zoneFk, date, geoIds, options) => {
|
||||
const models = Self.app.models;
|
||||
const myOptions = {};
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
if (!geoIds.lenght) throw new Error(`You must select a location`);
|
||||
|
||||
const newZoneExclusion = await models.ZoneExclusion.create({
|
||||
zoneFk: zoneFk,
|
||||
dated: date
|
||||
});
|
||||
}, myOptions);
|
||||
|
||||
const promises = [];
|
||||
|
||||
for (let geoId of geoIds) {
|
||||
await models.ZoneExclusionGeo.create({
|
||||
const newZoneExclusionGeo = await models.ZoneExclusionGeo.create({
|
||||
zoneExclusionFk: newZoneExclusion.id,
|
||||
geoFk: geoId.id
|
||||
});
|
||||
}, myOptions);
|
||||
|
||||
promises.push(newZoneExclusionGeo);
|
||||
}
|
||||
|
||||
const newZoneExclusionGeos = await Promise.all(promises);
|
||||
|
||||
return newZoneExclusionGeos;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
|
||||
describe('zone exclusionGeo()', () => {
|
||||
it('should create two exclusion by geo', async() => {
|
||||
const tx = await models.Zone.beginTransaction({});
|
||||
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
const today = new Date();
|
||||
const zoneId = 1;
|
||||
const geoIds = [{id: 1}, {id: 2}];
|
||||
const result = await models.Zone.exclusionGeo(zoneId, today, geoIds, options);
|
||||
|
||||
expect(result.length).toEqual(2);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue