1781-zoneHoliday #994
|
@ -1,2 +1,4 @@
|
||||||
INSERT INTO `salix`.`ACL`(`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
|
INSERT INTO `salix`.`ACL`(`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
|
||||||
vicent marked this conversation as resolved
Outdated
|
|||||||
VALUES('ZoneExclusionGeo', '*', '*', 'ALLOW', 'ROLE', 'employee');
|
VALUES
|
||||||
vicent marked this conversation as resolved
Outdated
carlosjr
commented
check ACL for this model check ACL for this model
|
|||||||
|
('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",
|
"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",
|
"date in the future": "Fecha en el futuro",
|
||||||
"reference duplicated": "Referencia duplicada",
|
"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 => {
|
module.exports = Self => {
|
||||||
vicent marked this conversation as resolved
carlosjr
commented
from from
|
|||||||
Self.remoteMethod('exclusionGeo', {
|
Self.remoteMethod('exclusionGeo', {
|
||||||
description: 'Exclude a zoneGeo for a zone',
|
description: 'Exclude a zoneGeo from a zone',
|
||||||
accepts: [
|
accepts: [
|
||||||
{
|
{
|
||||||
arg: 'zoneFk',
|
arg: 'zoneFk',
|
||||||
|
@ -30,19 +32,33 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
vicent marked this conversation as resolved
carlosjr
commented
where are my tests and my transaction? where are my tests and my transaction?
|
|||||||
});
|
});
|
||||||
|
|
||||||
Self.exclusionGeo = async(zoneFk, date, geoIds) => {
|
Self.exclusionGeo = async(zoneFk, date, geoIds, options) => {
|
||||||
const models = Self.app.models;
|
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({
|
const newZoneExclusion = await models.ZoneExclusion.create({
|
||||||
zoneFk: zoneFk,
|
zoneFk: zoneFk,
|
||||||
dated: date
|
dated: date
|
||||||
});
|
}, myOptions);
|
||||||
|
|
||||||
|
const promises = [];
|
||||||
|
|
||||||
for (let geoId of geoIds) {
|
for (let geoId of geoIds) {
|
||||||
await models.ZoneExclusionGeo.create({
|
const newZoneExclusionGeo = await models.ZoneExclusionGeo.create({
|
||||||
zoneExclusionFk: newZoneExclusion.id,
|
zoneExclusionFk: newZoneExclusion.id,
|
||||||
geoFk: geoId.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
Puedes mover este sql a la carpeta del sprint "junio" el de la familia aparece ya en tests y no se si va a dar problemas.