8062-testToMaster_2 #3059

Merged
alexm merged 293 commits from 8062-testToMaster_2 into master 2024-10-03 05:43:41 +00:00
3 changed files with 33 additions and 22 deletions
Showing only changes of commit 29b0851741 - Show all commits

View File

@ -1,4 +1,3 @@
-- Place your SQL code here
DROP TABLE IF EXISTS vn.wagonTypeTray;
CREATE TABLE vn.wagonTypeTray (
@ -20,7 +19,3 @@ ALTER TABLE vn.wagonConfig ADD CONSTRAINT wagonConfig_wagonTypeColor_FK FOREIGN
ALTER TABLE vn.wagonTypeTray DROP FOREIGN KEY wagonTypeTray_wagonType_FK;
ALTER TABLE vn.wagonTypeTray ADD CONSTRAINT wagonTypeTray_wagonType_FK FOREIGN KEY (wagonTypeFk) REFERENCES vn.wagonType(id) ON DELETE CASCADE ON UPDATE RESTRICT;
-- insertar datos por defecto

View File

@ -367,5 +367,9 @@
"It has been invoiced but the PDF of refund not be generated": "Se ha facturado pero no se ha podido generar el PDF del abono",
"Payment method is required": "El método de pago es obligatorio",
"Cannot send mail": "Não é possível enviar o email",
"CONSTRAINT `supplierAccountTooShort` failed for `vn`.`supplier`": "La cuenta debe tener exactamente 10 dígitos"
"CONSTRAINT `supplierAccountTooShort` failed for `vn`.`supplier`": "La cuenta debe tener exactamente 10 dígitos",
"There is already a tray with the same height": "Ya existe una bandeja con la misma altura",
"You must define wagon and height": "Debes definir un tipo de vagón y la altura",
"The maximum height of the wagon is": "La altura máxima es %d",
"The height must be greater than": "The height must be greater than %d"
}

View File

@ -1,16 +1,28 @@
// module.exports = Self => {
// Self.observe('before save', async ctx => {
// if (ctx.isNewInstance) {
// const models = Self.app.models;
// const config = await models.WagonConfig.findOne();
const UserError = require('vn-loopback/util/user-error');
// await models.WagonTypeTray.create({
// wagonTypeFk: config.wagonTypeFk,
// height: config.height,
// wagonTypeColorFk: config.wagonTypeColorFk
// }, ctx.options);
// }
// if (ctx.instance < config.minHeightBetweenTrays)
// throw new Error('Height must be greater than ' + config.minHeightBetweenTrays);
// });
// };
module.exports = Self => {
Self.observe('before save', async ctx => {
if (ctx.isNewInstance) {
const models = Self.app.models;
const {wagonTypeFk, height} = ctx.instance;
const trays = await models.WagonTypeTray.find({where: {wagonTypeFk}});
const config = await models.WagonConfig.findOne();
const tray = await models.WagonTypeTray.find({where: {wagonTypeFk, height}});
if (!trays.length) return;
if (tray.length)
throw new UserError('There is already a tray with the same height');
if (!wagonTypeFk && !height)
throw new UserError('You must define wagon and height');
if (height < config.minHeightBetweenTrays)
throw new UserError('The height must be greater than', 'HEIGHT_GREATER_THAN', config.minHeightBetweenTrays);
if (height > config.maxWagonHeight)
throw new UserError('The maximum height of the wagon is', 'MAX_WAGON_HEIGHT', config.maxWagonHeight);
}
});
};