From 25bd28990a3ea016f8885b7bd719a5e2b1f56e1d Mon Sep 17 00:00:00 2001 From: Bernat Date: Tue, 15 Oct 2019 14:44:00 +0200 Subject: [PATCH] Refactor #1812 refactor phone --- db/changes/10100-AllSaints/00-ACL.sql | 1 + db/changes/10100-AllSaints/00-userLog.sql | 18 ++++++ .../10100-AllSaints/00-userPhoneType.sql | 9 +++ db/changes/10100-AllSaints/01-userPhone.sql | 63 +++++++++++++++++++ db/dump/fixtures.sql | 12 ++-- modules/worker/back/model-config.json | 9 +++ modules/worker/back/models/user-log.json | 58 +++++++++++++++++ .../worker/back/models/user-phone-type.json | 18 ++++++ modules/worker/back/models/user-phone.json | 34 ++++++++++ 9 files changed, 215 insertions(+), 7 deletions(-) create mode 100644 db/changes/10100-AllSaints/00-ACL.sql create mode 100644 db/changes/10100-AllSaints/00-userLog.sql create mode 100644 db/changes/10100-AllSaints/00-userPhoneType.sql create mode 100644 db/changes/10100-AllSaints/01-userPhone.sql create mode 100644 modules/worker/back/models/user-log.json create mode 100644 modules/worker/back/models/user-phone-type.json create mode 100644 modules/worker/back/models/user-phone.json diff --git a/db/changes/10100-AllSaints/00-ACL.sql b/db/changes/10100-AllSaints/00-ACL.sql new file mode 100644 index 000000000..ea1ba706b --- /dev/null +++ b/db/changes/10100-AllSaints/00-ACL.sql @@ -0,0 +1 @@ +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('UserPhone', '*', 'WRITE', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/changes/10100-AllSaints/00-userLog.sql b/db/changes/10100-AllSaints/00-userLog.sql new file mode 100644 index 000000000..2e541eaf4 --- /dev/null +++ b/db/changes/10100-AllSaints/00-userLog.sql @@ -0,0 +1,18 @@ +CREATE TABLE `vn`.`userLog` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `originFk` int(11) NOT NULL, + `userFk` int(10) unsigned DEFAULT NULL, + `action` set('insert','update','delete') COLLATE utf8_unicode_ci NOT NULL, + `creationDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP, + `description` text CHARACTER SET utf8, + `changedModel` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, + `oldInstance` text COLLATE utf8_unicode_ci, + `newInstance` text COLLATE utf8_unicode_ci, + `changedModelId` int(11) DEFAULT NULL, + `changedModelValue` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `originFk` (`originFk`), + KEY `userFk` (`userFk`), + CONSTRAINT `userLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `userLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; \ No newline at end of file diff --git a/db/changes/10100-AllSaints/00-userPhoneType.sql b/db/changes/10100-AllSaints/00-userPhoneType.sql new file mode 100644 index 000000000..6bfedcc71 --- /dev/null +++ b/db/changes/10100-AllSaints/00-userPhoneType.sql @@ -0,0 +1,9 @@ +CREATE TABLE `vn`.`userPhoneType` ( + `code` VARCHAR(45) NOT NULL, + `description` VARCHAR(255) NULL, + PRIMARY KEY (`code`)); + + + +INSERT INTO `vn`.`userPhoneType` (`code`, `description`) VALUES ('businessPhone', 'Telefono de empresa del usuario'); +INSERT INTO `vn`.`userPhoneType` (`code`, `description`) VALUES ('personalPhone', 'Telefono personal del usuario'); diff --git a/db/changes/10100-AllSaints/01-userPhone.sql b/db/changes/10100-AllSaints/01-userPhone.sql new file mode 100644 index 000000000..488bbb112 --- /dev/null +++ b/db/changes/10100-AllSaints/01-userPhone.sql @@ -0,0 +1,63 @@ +CREATE TABLE `vn`.`userPhone` ( + `id` INT NOT NULL AUTO_INCREMENT, + `userFk` INT(10) UNSIGNED NOT NULL, + `typeFk` VARCHAR(45) NOT NULL, + `phone` INT(15) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE INDEX `UserFK_Phone` (`userFk` ASC, `phone` ASC)); + + +ALTER TABLE `vn`.`userPhone` +ADD CONSTRAINT `fgnTypeFk` + FOREIGN KEY (typeFk) + REFERENCES `vn`.`userPhoneType` (code) + ON DELETE RESTRICT + ON UPDATE CASCADE; + +ALTER TABLE `vn`.`userPhone` +ADD CONSTRAINT `fgnUserFk` + FOREIGN KEY (userFk) + REFERENCES `account`.`user` (id) + ON DELETE CASCADE + ON UPDATE CASCADE; + +insert into vn.userPhone(userFk,typeFk,phone) + select id,'PersonalPhone', phone + from vn.client + where phone is not null; + + +insert into vn.userPhone(userFk,typeFk,phone) + select id,'businessPhone', phone + from vn.worker + where phone is not null AND phone > ''; + +insert into vn.userPhone(userFk,typeFk,phone) + SELECT + `w`.`userFk`, + 'businessPhone', + `m`.`value` AS `mediaValue` + FROM + (((((`postgresql`.`person` `p` + JOIN `postgresql`.`profile` `po` ON ((`po`.`person_id` = `p`.`person_id`))) + JOIN `postgresql`.`profile_media` `pom` ON ((`pom`.`profile_id` = `po`.`profile_id`))) + JOIN `postgresql`.`media` `m` ON ((`m`.`media_id` = `pom`.`media_id`))) + JOIN `postgresql`.`media_type` `mt` ON ((`mt`.`media_type_id` = `m`.`media_type_id`))) + JOIN `vn`.`worker` `w` ON ((`w`.`id` = `p`.`id_trabajador`))) + WHERE + (`mt`.`name` = 'movil empresa'); + +insert into vn.userPhone(userFk,typeFk,phone) + SELECT + `w`.`userFk`, + 'personalPhone', + `m`.`value` AS `mediaValue` + FROM + (((((`postgresql`.`person` `p` + JOIN `postgresql`.`profile` `po` ON ((`po`.`person_id` = `p`.`person_id`))) + JOIN `postgresql`.`profile_media` `pom` ON ((`pom`.`profile_id` = `po`.`profile_id`))) + JOIN `postgresql`.`media` `m` ON ((`m`.`media_id` = `pom`.`media_id`))) + JOIN `postgresql`.`media_type` `mt` ON ((`mt`.`media_type_id` = `m`.`media_type_id`))) + JOIN `vn`.`worker` `w` ON ((`w`.`id` = `p`.`id_trabajador`))) + WHERE + (`mt`.`name` = 'movil personal') \ No newline at end of file diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 5cb81b420..2624f1768 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -199,8 +199,8 @@ INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city (108, 'Charles Xavier', '22641921P', 'Professor X', 'Beast', '3800 Victory Pkwy, Cincinnati, OH 45207, USA', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'CharlesXavier@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 1, NULL, 0, 0, 19, 0, 1), (109, 'Bruce Banner', '16104829E', 'Hulk', 'Black widow', 'Somewhere in New York', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'BruceBanner@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 0, 0, NULL, 0, 0, 19, 0, 1), (110, 'Jessica Jones', '58282869H', 'Jessica Jones', 'Luke Cage', 'NYCC 2015 Poster', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'JessicaJones@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 0, 0, NULL, 0, 0, NULL, 0, 1), - (200, 'Missing', NULL, 'Missing man', 'Anton', 'The space', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, NULL, 1, 0, 1, 0, NULL, 1, 0, NULL, 0, 1), - (400, 'Trash', NULL, 'Garbage man', 'Unknown name', 'New York city', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, NULL, 1, 0, 1, 0, NULL, 1, 0, NULL, 0, 1); + (111, 'Missing', NULL, 'Missing man', 'Anton', 'The space', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, NULL, 1, 0, 1, 0, NULL, 1, 0, NULL, 0, 1), + (112, 'Trash', NULL, 'Garbage man', 'Unknown name', 'New York city', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, NULL, 1, 0, 1, 0, NULL, 1, 0, NULL, 0, 1); INSERT INTO `vn`.`client`(`id`, `name`, `fi`, `socialName`, `contact`, `street`, `city`, `postcode`, `phone`, `isRelevant`, `email`, `iban`,`dueDay`,`accountingAccount`, `isEqualizated`, `provinceFk`, `hasToInvoice`, `credit`, `countryFk`, `isActive`, `gestdocFk`, `quality`, `payMethodFk`,`created`, `isTaxDataChecked`) SELECT id, name, CONCAT(RPAD(CONCAT(id,9),8,id),'A'), CONCAT(name, 'Social'), CONCAT(name, 'Contact'), CONCAT(name, 'Street'), 'SILLA', 46460, 623111111, 1, CONCAT(name,'@mydomain.com'), NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5, CURDATE(), 1 @@ -226,8 +226,8 @@ INSERT INTO `vn`.`address`(`id`, `nickname`, `street`, `city`, `postalCode`, `pr (8, 'Charles Xavier', '3800 Victory Pkwy, Cincinnati, OH 45207, USA', 'Silla', 46460, 1, 1111111111, 222222222, 1, 108, 2, NULL, NULL, 0, 1), (9, 'Bruce Banner', 'Somewhere in New York', 'Silla', 46460, 1, 1111111111, 222222222, 1, 109, 2, NULL, NULL, 0, 1), (10, 'Jessica Jones', 'NYCC 2015 Poster', 'Silla', 46460, 1, 1111111111, 222222222, 1, 110, 2, NULL, NULL, 0, 1), - (11, 'Missing', 'The space', 'Silla', 46460, 1, 1111111111, 222222222, 1, 200, 10, NULL, NULL, 0, 1), - (12, 'Trash', 'New York city', 'Silla', 46460, 1, 1111111111, 222222222, 1, 400, 10, NULL, NULL, 0, 1), + (11, 'Missing', 'The space', 'Silla', 46460, 1, 1111111111, 222222222, 1, 111, 10, NULL, NULL, 0, 1), + (12, 'Trash', 'New York city', 'Silla', 46460, 1, 1111111111, 222222222, 1, 112, 10, NULL, NULL, 0, 1), (101, 'address 01', 'Somewhere in Thailand', 'Silla', 46460, 1, 1111111111, 222222222, 1, 109, 2, NULL, NULL, 0, 0), (102, 'address 02', 'Somewhere in Poland', 'Silla', 46460, 1, 3333333333, 444444444, 1, 109, 2, NULL, NULL, 0, 0), (103, 'address 03', 'Somewhere in Japan', 'Silla', 46460, 1, 3333333333, 444444444, 1, 109, 2, NULL, NULL, 0, 0), @@ -257,9 +257,7 @@ INSERT INTO `vn`.`address`(`id`, `nickname`, `street`, `city`, `postalCode`, `pr (127, 'address 27', 'Your pocket', 'Silla', 46460, 1, 1111111111, 222222222, 1, 107, 2, NULL, NULL, 0, 0), (128, 'address 28', 'Cerebro', 'Silla', 46460, 1, 1111111111, 222222222, 1, 108, 2, NULL, NULL, 0, 0), (129, 'address 29', 'Luke Cages Bar', 'Silla', 46460, 1, 1111111111, 222222222, 1, 110, 2, NULL, NULL, 0, 0), - (130, 'address 30', 'Non valid address', 'Silla', 46460, 1, 1111111111, 222222222, 0, 101, 2, NULL, NULL, 0, 0), - (131, 'Missing', 'The space', 'Silla', 46460, 1, 1111111111, 222222222, 1, 200, 10, NULL, NULL, 0, 0), - (132, 'Trash', 'New York city', 'Silla', 46460, 1, 1111111111, 222222222, 1, 400, 10, NULL, NULL, 0, 0); + (130, 'address 30', 'Non valid address', 'Silla', 46460, 1, 1111111111, 222222222, 0, 101, 2, NULL, NULL, 0, 0); INSERT INTO `vn`.`address`( `nickname`, `street`, `city`, `postalCode`, `provinceFk`, `isActive`, `clientFk`, `agencyModeFk`, `isDefaultAddress`) SELECT name, CONCAT(name, 'Street'), 'SILLA', 46460, 1, 1, id, 2, 1 diff --git a/modules/worker/back/model-config.json b/modules/worker/back/model-config.json index 35a039d3c..df2b776fb 100644 --- a/modules/worker/back/model-config.json +++ b/modules/worker/back/model-config.json @@ -49,5 +49,14 @@ }, "Device": { "dataSource": "vn" + }, + "UserPhoneType": { + "dataSource": "vn" + }, + "UserPhone": { + "dataSource": "vn" + }, + "UserLog": { + "dataSource": "vn" } } diff --git a/modules/worker/back/models/user-log.json b/modules/worker/back/models/user-log.json new file mode 100644 index 000000000..e3e3a6752 --- /dev/null +++ b/modules/worker/back/models/user-log.json @@ -0,0 +1,58 @@ +{ + "name": "UserLog", + "base": "VnModel", + "options": { + "mysql": { + "table": "userLog" + } + }, + "properties": { + "id": { + "id": true, + "type": "Number", + "forceId": false + }, + "originFk": { + "type": "Number", + "required": true + }, + "userFk": { + "type": "Number" + }, + "action": { + "type": "String", + "required": true + }, + "changedModel": { + "type": "String" + }, + "oldInstance": { + "type": "Object" + }, + "newInstance": { + "type": "Object" + }, + "creationDate": { + "type": "Date" + }, + "changedModelId": { + "type": "Number" + }, + "changedModelValue": { + "type": "String" + }, + "description": { + "type": "String" + } + }, + "relations": { + "user": { + "type": "belongsTo", + "model": "Account", + "foreignKey": "userFk" + } + }, + "scope": { + "order": ["creationDate DESC", "id DESC"] + } +} diff --git a/modules/worker/back/models/user-phone-type.json b/modules/worker/back/models/user-phone-type.json new file mode 100644 index 000000000..479f02d6f --- /dev/null +++ b/modules/worker/back/models/user-phone-type.json @@ -0,0 +1,18 @@ +{ + "name": "UserPhoneType", + "base": "VnModel", + "options": { + "mysql": { + "table": "userPhoneType" + } + }, + "properties": { + "code": { + "id": true, + "type": "String" + }, + "description": { + "type": "String" + } + } +} diff --git a/modules/worker/back/models/user-phone.json b/modules/worker/back/models/user-phone.json new file mode 100644 index 000000000..c869a808d --- /dev/null +++ b/modules/worker/back/models/user-phone.json @@ -0,0 +1,34 @@ +{ + "name": "UserPhone", + "base": "Loggable", + "log": { + "model":"UserLog" + }, + "options": { + "mysql": { + "table": "userPhone" + } + }, + "properties": { + "id": { + "id": true, + "type": "String" + }, + "phone": { + "type": "Number", + "required": true + } + }, + "relations": { + "user": { + "type": "belongsTo", + "model": "Account", + "foreignKey": "userFk" + }, + "type": { + "type": "belongsTo", + "model": "UserPhoneType", + "foreignKey": "typeFk" + } + } +}