From 81eabac30bcfccc09edbdbc8728e7694e1185857 Mon Sep 17 00:00:00 2001 From: Bernat Date: Mon, 12 Nov 2018 11:50:16 +0100 Subject: [PATCH] update model ticketRequest and update structure DB --- .../install/changes/1.2-CHECK/11.ordenes.sql | 47 +++++++++++++++++++ ...ticketRequest.sql => 12.ticketRequest.sql} | 3 +- services/db/install/dump/fixtures.sql | 10 ++-- .../common/models/ticket-request.json | 23 +++++---- 4 files changed, 69 insertions(+), 14 deletions(-) create mode 100644 services/db/install/changes/1.2-CHECK/11.ordenes.sql rename services/db/install/changes/1.2-CHECK/{11.ticketRequest.sql => 12.ticketRequest.sql} (85%) diff --git a/services/db/install/changes/1.2-CHECK/11.ordenes.sql b/services/db/install/changes/1.2-CHECK/11.ordenes.sql new file mode 100644 index 000000000..520113704 --- /dev/null +++ b/services/db/install/changes/1.2-CHECK/11.ordenes.sql @@ -0,0 +1,47 @@ +ALTER TABLE `vn2008`.`Ordenes` +ADD COLUMN `isOk` TINYINT(1) NULL DEFAULT NULL AFTER `odbc_date`, +ADD COLUMN `requesterFk` INT(11) NULL DEFAULT NULL AFTER `isOk`, +ADD COLUMN `atenderFk` INT(11) NULL DEFAULT NULL AFTER `requesterFk`; + +ALTER TABLE `vn2008`.`Ordenes` +ADD COLUMN `ticketFk` INT(11) NULL DEFAULT NULL AFTER `atenderFk`; + + + +ALTER TABLE `vn2008`.`Ordenes` +ADD INDEX `fgnRequester_idx` (`requesterFk` ASC), +ADD INDEX `fgnAtender_idx` (`atenderFk` ASC); +ALTER TABLE `vn2008`.`Ordenes` +ADD CONSTRAINT `fgnRequester` +FOREIGN KEY (`requesterFk`) +REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) +ON DELETE RESTRICT +ON UPDATE CASCADE, +ADD CONSTRAINT `fgnAtender` +FOREIGN KEY (`atenderFk`) +REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) +ON DELETE RESTRICT +ON UPDATE CASCADE, +ADD CONSTRAINT `fgbMovimiento` +FOREIGN KEY (`Id_Movimiento`) +REFERENCES `vn2008`.`Movimientos` (`Id_Movimiento`) +ON DELETE RESTRICT +ON UPDATE CASCADE; + +ALTER TABLE `vn2008`.`Ordenes` +DROP FOREIGN KEY `fgbMovimiento`; +ALTER TABLE `vn2008`.`Ordenes` +ADD CONSTRAINT `fgbMovimiento` + FOREIGN KEY (`Id_Movimiento`) + REFERENCES `vn2008`.`Movimientos` (`Id_Movimiento`) + ON DELETE SET NULL + ON UPDATE CASCADE; + +ALTER TABLE `vn2008`.`Ordenes` +ADD INDEX `fgnTicket_idx` (`ticketFk` ASC); +ALTER TABLE `vn2008`.`Ordenes` +ADD CONSTRAINT `fgnTicket` + FOREIGN KEY (`ticketFk`) + REFERENCES `vn2008`.`Tickets` (`Id_Ticket`) + ON DELETE RESTRICT + ON UPDATE CASCADE; diff --git a/services/db/install/changes/1.2-CHECK/11.ticketRequest.sql b/services/db/install/changes/1.2-CHECK/12.ticketRequest.sql similarity index 85% rename from services/db/install/changes/1.2-CHECK/11.ticketRequest.sql rename to services/db/install/changes/1.2-CHECK/12.ticketRequest.sql index 5fd0276f1..87451c481 100644 --- a/services/db/install/changes/1.2-CHECK/11.ticketRequest.sql +++ b/services/db/install/changes/1.2-CHECK/12.ticketRequest.sql @@ -7,12 +7,13 @@ VIEW `ticketRequest` AS SELECT `t`.`Id_ORDEN` AS `id`, `t`.`ORDEN` AS `description`, - `t`.`CodVENDEDOR` AS `requestFk`, + `t`.`requesterFk` AS `requesterFk`, `t`.`CodCOMPRADOR` AS `atenderFk`, `t`.`CANTIDAD` AS `quantity`, `t`.`PRECIOMAX` AS `price`, `t`.`KO` AS `isOk`, `t`.`Id_Movimiento` AS `saleFk`, + `t`.`ticketFk` AS `ticketFk`, `t`.`odbc_date` AS `created` FROM `vn2008`.`Ordenes` `t`; diff --git a/services/db/install/dump/fixtures.sql b/services/db/install/dump/fixtures.sql index 89b79d003..d965aba77 100644 --- a/services/db/install/dump/fixtures.sql +++ b/services/db/install/dump/fixtures.sql @@ -1019,9 +1019,9 @@ INSERT INTO `vn2008`.`workerTeam`(`id`, `team`, `user`) (5, 3, 103), (6, 3, 104); -INSERT INTO `vn`.`ticketRequest`(`id`, `description`, `requestFk`, `atenderFk`, `quantity`, `price`, `isOk`, `saleFk`, `created`) +INSERT INTO `vn`.`ticketRequest`(`id`, `description`, `requesterFk`, `atenderFk`, `quantity`, `price`, `isOk`, `saleFk`, `ticketFk`, `created`) VALUES - (1, 'Gem of Time', '018', '035', 5, 9.10, 0, 1, DATE_ADD(CURDATE(), INTERVAL -15 DAY)), - (2, 'Gem of Mind', '018', '035', 10, 1.07, 0, 2, DATE_ADD(CURDATE(), INTERVAL -15 DAY)), - (3, 'Mark I', '018', '035', 20, 3.06, 0, 4, DATE_ADD(CURDATE(), INTERVAL -15 DAY)), - (4, 'Gem of Mind', '018', '035', 15, 1.30, 0, 7, CURDATE()); \ No newline at end of file + (1, 'Gem of Time', 18, 35, 5, 9.10, 1, 1, 1, DATE_ADD(CURDATE(), INTERVAL -15 DAY)), + (2, 'Gem of Mind', 18, 35, 10, 1.07, 0, 2, 1, DATE_ADD(CURDATE(), INTERVAL -15 DAY)), + (3, 'Mark I', 18, 35, 20, 3.06, 0, NULL, 1, DATE_ADD(CURDATE(), INTERVAL -15 DAY)), + (4, 'Gem of Mind', 18, 35, 15, 1.30, 0, NULL, 11, CURDATE()); \ No newline at end of file diff --git a/services/loopback/common/models/ticket-request.json b/services/loopback/common/models/ticket-request.json index 504b67d81..cfb23a14f 100644 --- a/services/loopback/common/models/ticket-request.json +++ b/services/loopback/common/models/ticket-request.json @@ -26,14 +26,6 @@ }, "isOk": { "type": "Boolean" - }, - "atender": { - "type": "String", - "columnName": "atenderFk" - }, - "requester": { - "type": "String", - "columnName": "requesterFk" } }, "relations": { @@ -41,6 +33,21 @@ "type": "belongsTo", "model": "Sale", "foreignKey": "saleFk" + }, + "ticket": { + "type": "belongsTo", + "model": "Ticket", + "foreignKey": "ticketFk" + }, + "atender": { + "type": "belongsTo", + "model": "Worker", + "foreignKey": "atenderFk" + }, + "requester": { + "type": "belongsTo", + "model": "Worker", + "foreignKey": "requesterFk" } } } \ No newline at end of file