Compare commits

...

2 Commits

Author SHA1 Message Date
Alexandre Riera 530c300ea5 declaring models deliveryMan
gitea/salix/pipeline/head This commit looks good Details
2022-12-01 15:15:46 +01:00
Alexandre Riera 8a3231b615 working on routes
gitea/salix/pipeline/head This commit looks good Details
2022-11-30 08:35:56 +01:00
8 changed files with 182 additions and 3 deletions

View File

@ -0,0 +1,26 @@
CREATE TABLE `vn`.`routeDeliveryMan` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`supplierFk` int(11) DEFAULT NULL,
`minCost` decimal(10,0) DEFAULT NULL,
`minM3` int(10) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `routeDeliveryMan_FK` (`supplierFk`),
CONSTRAINT `routeDeliveryMan_FK` FOREIGN KEY (`supplierFk`) REFERENCES `vn`.`supplier` (`id`) ON UPDATE CASCADE
) ENGINE=InnoDB;
CREATE TABLE `vn`.`routeDeliveryManAgency` (
`deliveryManFk` int(10) unsigned NOT NULL,
`agencyModeFk` int(11) NOT NULL,
PRIMARY KEY (`deliveryManFk`),
KEY `routeDeliveryManAgency_FK` (`agencyModeFk`),
CONSTRAINT `routeDeliveryManAgency_FK` FOREIGN KEY (`agencyModeFk`) REFERENCES `agencyMode` (`id`) ON UPDATE CASCADE,
CONSTRAINT `routeDeliveryManAgency_FK_1` FOREIGN KEY (`deliveryManFk`) REFERENCES `routeDeliveryMan` (`id`) ON UPDATE CASCADE
) ENGINE=InnoDB;
ALTER TABLE `vn`.`route` ADD `invoiceOutFk` varchar(10) NULL;
ALTER TABLE `vn`.`route` ADD CONSTRAINT `route_FK` FOREIGN KEY (`invoiceOutFk`) REFERENCES `vn`.`invoiceOut`(`ref`) ON DELETE RESTRICT ON UPDATE CASCADE;
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
VALUES
('DeliveryMan', '*', '*', 'ALLOW', 'ROLE', 'employee'),
('DeliveryManAgency', '*', '*', 'ALLOW', 'ROLE', 'employee');

View File

@ -1 +0,0 @@
Delete this file

View File

@ -1798,7 +1798,7 @@ INSERT INTO `vn`.`claimRatio`(`clientFk`, `yearSale`, `claimAmount`, `claimingRa
(1103, 2000, 0.00, 0.00, 0.02, 1.00),
(1104, 2500, 150.00, 0.02, 0.10, 1.00);
INSERT INTO vn.claimRma (`id`, `code`, `created`, `workerFk`)
INSERT INTO `vn`.`claimRma` (`id`, `code`, `created`, `workerFk`)
VALUES
(1, '02676A049183', DEFAULT, 1106),
(2, '02676A049183', DEFAULT, 1106),
@ -1806,7 +1806,13 @@ INSERT INTO vn.claimRma (`id`, `code`, `created`, `workerFk`)
(4, '02676A049183', DEFAULT, 1107),
(5, '01837B023653', DEFAULT, 1106);
INSERT INTO `vn`.`routeDeliveryMan` (`id`, `supplierFk`, `minCost`, `minM3`)
VALUES
(1, 442, 10.0, 10);
INSERT INTO `vn`.`routeDeliveryManAgency` (`deliveryManFk`, `agencyModeFk`)
VALUES
(1, 1);
INSERT INTO `hedera`.`tpvMerchant`(`id`, `description`, `companyFk`, `bankFk`, `secretKey`)
VALUES

View File

@ -0,0 +1,75 @@
module.exports = Self => {
Self.remoteMethod('updateDeliveryMan', {
description: 'Updates delivery man data',
accepts: [
{
arg: 'ctx',
type: 'object',
http: {source: 'context'}
},
{
arg: 'id',
type: 'number',
required: false,
description: 'The delivery man id',
},
{
arg: 'minCost',
type: 'number'
},
{
arg: 'minM3',
type: 'number'
},
{
arg: 'agencyFk',
type: 'number'
},
{
arg: 'supplierFk',
type: 'number'
}
],
accessType: 'WRITE',
returns: {
type: 'Object',
root: true
},
http: {
path: `/updateDeliveryMan/:id`,
verb: 'PATCH'
}
});
Self.updateDeliveryMan = async(ctx, id, options) => {
const models = Self.app.models;
const args = ctx.args;
let tx;
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
try {
const deliveryMan = await models.DeliveryMan.findById(id, null, myOptions);
await deliveryMan.updateAttributes({
minCost: args.minCost,
minM3: args.minM3,
supplierFk: args.supplierFk
}, myOptions);
if (tx) await tx.commit();
return deliveryMan;
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
};

View File

@ -16,6 +16,12 @@
},
"DeliveryPoint": {
"dataSource": "vn"
},
"DeliveryMan": {
"dataSource": "vn"
},
"DeliveryManAgency": {
"dataSource": "vn"
}
}

View File

@ -0,0 +1,37 @@
{
"name": "DeliveryMan",
"base": "VnModel",
"options": {
"mysql": {
"table": "routeDeliveryMan"
}
},
"properties": {
"id": {
"id": true,
"type": "number",
"forceId": false
},
"supplierFk": {
"type": "number"
},
"minCost": {
"type": "number"
},
"minM3": {
"type": "number"
}
},
"relations": {
"supplier": {
"type": "belongsTo",
"model": "Supplier",
"foreignKey": "supplierFk"
},
"deliveryManAgency": {
"type": "hasOne",
"model": "DeliveryManAgency",
"foreignKey": "deliveryManFk"
}
}
}

View File

@ -0,0 +1,29 @@
{
"name": "DeliveryManAgency",
"base": "VnModel",
"options": {
"mysql": {
"table": "routeDeliveryManAgency"
}
},
"properties": {
"deliveryManFk": {
"id": true
},
"agencyModeFk": {
"id": true
}
},
"relations": {
"deliveryMan": {
"type": "belongsTo",
"model": "DeliveryMan",
"foreignKey": "deliveryManFk"
},
"agencyMode": {
"type": "belongsTo",
"model": "AgencyMode",
"foreignKey": "agencyModeFk"
}
}
}

View File

@ -13,6 +13,7 @@ module.exports = Self => {
require('../methods/route/driverRoutePdf')(Self);
require('../methods/route/driverRouteEmail')(Self);
require('../methods/route/sendSms')(Self);
require('../methods/route/updateDeliveryMan')(Self);
Self.validate('kmStart', validateDistance, {
message: 'Distance must be lesser than 1000'