feat: refs #7248 modify column workerFk to userFK
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Robert Ferrús 2025-02-05 13:30:40 +01:00
parent 4bd92f2cb2
commit eaea108e62
20 changed files with 119 additions and 85 deletions

View File

@ -528,7 +528,7 @@ INSERT INTO `vn`.`roleCreditLimit`(`id`, `maxAmount`, `roleFk`)
(2, 10000, 21), (2, 10000, 21),
(3, 600, 13); (3, 600, 13);
INSERT INTO `vn`.`clientObservation`(`id`, `clientFk`, `workerFk`, `text`, `created`) INSERT INTO `vn`.`clientObservation`(`id`, `clientFk`, `userFk`, `text`, `created`)
VALUES VALUES
(1, 1101, 1, 'Madness, as you know, is like gravity, all it takes is a little push', util.VN_CURDATE()), (1, 1101, 1, 'Madness, as you know, is like gravity, all it takes is a little push', util.VN_CURDATE()),
(2, 1102, 1, 'With great power, comes great responsibility', util.VN_CURDATE()), (2, 1102, 1, 'With great power, comes great responsibility', util.VN_CURDATE()),
@ -554,12 +554,12 @@ INSERT INTO `vn`.`observationType`(`id`,`description`, `code`)
(9, 'Sustitución', 'substitution'), (9, 'Sustitución', 'substitution'),
(10, 'Finance', 'finance'); (10, 'Finance', 'finance');
INSERT INTO `vn`.`addressObservation`(`id`,`addressFk`,`observationTypeFk`,`description`) INSERT INTO `vn`.`addressObservation`(`id`,`addressFk`, `userFk`,`observationTypeFk`,`description`)
VALUES VALUES
(1, 121, 1, 'under the floor'), (1, 121, 1, 1, 'under the floor'),
(2, 121, 2, 'wears leather and goes out at night'), (2, 121, 1, 2, 'wears leather and goes out at night'),
(3, 121, 3, 'care with the dog'), (3, 121, 1, 3, 'care with the dog'),
(5, 122, 5, 'Delivery after 10am'); (5, 122, 1, 5, 'Delivery after 10am');
INSERT INTO `vn`.`creditClassification`(`id`, `client`, `dateStart`, `dateEnd`) INSERT INTO `vn`.`creditClassification`(`id`, `client`, `dateStart`, `dateEnd`)
VALUES VALUES
@ -802,22 +802,22 @@ INSERT INTO `vn`.`ticket`(`id`, `priority`, `agencyModeFk`,`warehouseFk`,`routeF
(36, 1, 1, 1, 3, util.VN_CURDATE(), util.VN_CURDATE(), 1102, 'Ant-Man Adventure', 123, NULL, 0, 1, 16, 0, util.VN_CURDATE(), NULL, NULL, NULL, NULL), (36, 1, 1, 1, 3, util.VN_CURDATE(), util.VN_CURDATE(), 1102, 'Ant-Man Adventure', 123, NULL, 0, 1, 16, 0, util.VN_CURDATE(), NULL, NULL, NULL, NULL),
(37, 1, 1, 1, 3, util.VN_CURDATE(), util.VN_CURDATE(), 1110, 'Deadpool swords', 123, NULL, 0, 1, 16, 0, util.VN_CURDATE(), NULL, NULL, NULL, NULL); (37, 1, 1, 1, 3, util.VN_CURDATE(), util.VN_CURDATE(), 1110, 'Deadpool swords', 123, NULL, 0, 1, 16, 0, util.VN_CURDATE(), NULL, NULL, NULL, NULL);
INSERT INTO `vn`.`ticketObservation`(`id`, `ticketFk`, `observationTypeFk`, `description`) INSERT INTO `vn`.`ticketObservation`(`id`, `ticketFk`,`userFk`, `observationTypeFk`, `description`)
VALUES VALUES
(1, 11, 1, 'ready'), (1, 11, 1, 1, 'ready'),
(2, 2, 2, 'do it fast please'), (2, 2, 1, 2, 'do it fast please'),
(3, 3, 5, 'Faster faster fasteeeeeer!!!'), (3, 3, 1, 5, 'Faster faster fasteeeeeer!!!'),
(4, 4, 5, 'Deliver before 8am'), (4, 4, 2, 5, 'Deliver before 8am'),
(5, 13, 5, 'You can run from the disappointments you are trying to forget. But its only when you embrace your past that you truly move forward. Maybe I never get to go home again, but I found my way there. And I am glad I did.'), (5, 13, 2, 5, 'You can run from the disappointments you are trying to forget. But its only when you embrace your past that you truly move forward. Maybe I never get to go home again, but I found my way there. And I am glad I did.'),
(6, 14, 5, 'Careful, armed warhead'), (6, 14, 2, 5, 'Careful, armed warhead'),
(7, 23, 1, 'under the floor'), (7, 23, 2, 1, 'under the floor'),
(8, 23, 2, 'wears leather and goes out at night'), (8, 23, 2, 2, 'wears leather and goes out at night'),
(9, 23, 5, 'care with the dog'), (9, 23, 2, 5, 'care with the dog'),
(10, 23, 4, 'Reclama ticket: 8'), (10, 23, 2, 4, 'Reclama ticket: 8'),
(11, 24, 4, 'Reclama ticket: 7'), (11, 24, 2, 4, 'Reclama ticket: 7'),
(12, 11, 3, 'Delivery after 10am'), (12, 11, 2, 3, 'Delivery after 10am'),
(13, 1, 7, 'observation of ticket one'), (13, 1, 2, 7, 'observation of ticket one'),
(14, 2, 7, 'observation of ticket two'); (14, 2, 2, 7, 'observation of ticket two');
-- FIX for state hours on local, inter_afterInsert -- FIX for state hours on local, inter_afterInsert
-- UPDATE vncontrol.inter SET odbc_date = DATE_ADD(util.VN_CURDATE(), INTERVAL -10 SECOND); -- UPDATE vncontrol.inter SET odbc_date = DATE_ADD(util.VN_CURDATE(), INTERVAL -10 SECOND);
@ -1912,7 +1912,7 @@ INSERT INTO `vn`.`claim`(`id`, `ticketCreated`, `claimStateFk`, `clientFk`, `wor
(3, util.VN_CURDATE(), 3, 1101, 19, 1, 1, util.VN_CURDATE(), 5, 7), (3, util.VN_CURDATE(), 3, 1101, 19, 1, 1, util.VN_CURDATE(), 5, 7),
(4, util.VN_CURDATE(), 3, 1104, 18, 5, 0, util.VN_CURDATE(), 10, 8); (4, util.VN_CURDATE(), 3, 1104, 18, 5, 0, util.VN_CURDATE(), 10, 8);
INSERT INTO `vn`.`claimObservation` (`claimFk`, `workerFk`, `text`, `created`) INSERT INTO `vn`.`claimObservation` (`claimFk`, `userFk`, `text`, `created`)
VALUES VALUES
(1, 18, 'Cu nam labores lobortis definiebas, ei aliquyam salutatus persequeris quo, cum eu nemore fierent dissentiunt. Per vero dolor id, vide democritum scribentur eu vim, pri erroribus temporibus ex.', util.VN_CURDATE()), (1, 18, 'Cu nam labores lobortis definiebas, ei aliquyam salutatus persequeris quo, cum eu nemore fierent dissentiunt. Per vero dolor id, vide democritum scribentur eu vim, pri erroribus temporibus ex.', util.VN_CURDATE()),
(2, 18, 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.', util.VN_CURDATE()), (2, 18, 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.', util.VN_CURDATE()),

View File

@ -4,5 +4,6 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`addressObservation_befo
FOR EACH ROW FOR EACH ROW
BEGIN BEGIN
SET NEW.editorFk = account.myUser_getId(); SET NEW.editorFk = account.myUser_getId();
SET NEW.userFk = account.myUser_getId();
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -4,5 +4,6 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`claimObservation_before
FOR EACH ROW FOR EACH ROW
BEGIN BEGIN
SET NEW.editorFk = account.myUser_getId(); SET NEW.editorFk = account.myUser_getId();
SET NEW.userFk = account.myUser_getId();
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -4,5 +4,6 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`clientObservation_befor
FOR EACH ROW FOR EACH ROW
BEGIN BEGIN
SET NEW.editorFk = account.myUser_getId(); SET NEW.editorFk = account.myUser_getId();
SET NEW.userFk = account.myUser_getId();
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -4,5 +4,6 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`entryObservation_before
FOR EACH ROW FOR EACH ROW
BEGIN BEGIN
SET NEW.editorFk = account.myUser_getId(); SET NEW.editorFk = account.myUser_getId();
SET NEW.userFk = account.myUser_getId();
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -4,5 +4,6 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`ticketObservation_befor
FOR EACH ROW FOR EACH ROW
BEGIN BEGIN
SET NEW.editorFk = account.myUser_getId(); SET NEW.editorFk = account.myUser_getId();
SET NEW.userFk = account.myUser_getId();
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -4,5 +4,6 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`travelObservation_befor
FOR EACH ROW FOR EACH ROW
BEGIN BEGIN
SET NEW.editorFk = account.myUser_getId(); SET NEW.editorFk = account.myUser_getId();
SET NEW.userFk = account.myUser_getId();
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -4,5 +4,6 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`workerObservation_befor
FOR EACH ROW FOR EACH ROW
BEGIN BEGIN
SET NEW.editorFk = account.myUser_getId(); SET NEW.editorFk = account.myUser_getId();
SET NEW.userFk = account.myUser_getId();
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -2,9 +2,51 @@ ALTER TABLE vn.travelObservation ADD COLUMN IF NOT EXISTS `editorFk` int(10) uns
ALTER TABLE vn.workerObservation ADD COLUMN IF NOT EXISTS `editorFk` int(10) unsigned DEFAULT NULL; ALTER TABLE vn.workerObservation ADD COLUMN IF NOT EXISTS `editorFk` int(10) unsigned DEFAULT NULL;
ALTER TABLE vn.addressObservation ADD COLUMN IF NOT EXISTS `editorFk` int(10) unsigned DEFAULT NULL; ALTER TABLE vn.addressObservation ADD COLUMN IF NOT EXISTS `editorFk` int(10) unsigned DEFAULT NULL;
ALTER TABLE vn.entryObservation ADD COLUMN IF NOT EXISTS `userFk` int(10) unsigned DEFAULT NULL; ALTER TABLE vn.entryObservation ADD COLUMN IF NOT EXISTS `userFk` int(10) unsigned NOT NULL AFTER entryFk;
ALTER TABLE vn.ticketObservation ADD COLUMN IF NOT EXISTS `userFk` int(10) unsigned DEFAULT NULL; ALTER TABLE vn.ticketObservation ADD COLUMN IF NOT EXISTS `userFk` int(10) unsigned NOT NULL AFTER ticketFk;
ALTER TABLE vn.addressObservation ADD COLUMN IF NOT EXISTS `userFk` int(10) unsigned DEFAULT NULL; ALTER TABLE vn.addressObservation ADD COLUMN IF NOT EXISTS `userFk` int(10) unsigned NOT NULL AFTER addressFk;
ALTER TABLE IF EXISTS `vn`.`claimObservation`
CHANGE COLUMN IF EXISTS `workerFk` `userFk` int(10) unsigned DEFAULT NULL;
ALTER TABLE IF EXISTS `vn`.`clientObservation`
CHANGE COLUMN IF EXISTS `workerFk` `userFk` int(10) unsigned DEFAULT NULL;
ALTER TABLE vn.travelObservation MODIFY COLUMN userFk int(10) NOT NULL; ALTER TABLE vn.travelObservation MODIFY COLUMN userFk int(10) NOT NULL;
ALTER TABLE vn.claimObservation DROP FOREIGN KEY claimObservation_ibfk_2;
ALTER TABLE vn.clientObservation DROP FOREIGN KEY clientObservation_ibfk_2;
ALTER TABLE vn.workerObservation DROP FOREIGN KEY workerFk_workerObservation_FK;
ALTER TABLE vn.claimObservation
ADD CONSTRAINT userFk_claimObservation_FK FOREIGN KEY (userFk)
REFERENCES `account`.`user` (`id`)
ON DELETE CASCADE
ON UPDATE CASCADE;
ALTER TABLE vn.clientObservation
ADD CONSTRAINT userFk_clientObservation FOREIGN KEY (userFk)
REFERENCES `account`.`user` (`id`)
ON DELETE CASCADE
ON UPDATE CASCADE;
ALTER TABLE vn.entryObservation
ADD CONSTRAINT userFk_entryObservation FOREIGN KEY (userFk)
REFERENCES `account`.`user` (`id`)
ON DELETE CASCADE
ON UPDATE CASCADE;
ALTER TABLE vn.ticketObservation
ADD CONSTRAINT userFk_ticketObservation FOREIGN KEY (userFk)
REFERENCES `account`.`user` (`id`)
ON DELETE CASCADE
ON UPDATE CASCADE;
ALTER TABLE vn.addressObservation
ADD CONSTRAINT userFk_addressObservation FOREIGN KEY (userFk)
REFERENCES `account`.`user` (`id`)
ON DELETE CASCADE
ON UPDATE CASCADE;

View File

@ -88,14 +88,12 @@ module.exports = Self => {
// Claim observations // Claim observations
filter = { filter = {
where: {claimFk: id}, where: {claimFk: id},
include: [ include: {
{ relation: 'user',
relation: 'worker', scope: {
scope: { fields: ['id'],
fields: ['id', 'firstName', 'lastName'] },
} },
}
]
}; };
promises.push(models.ClaimObservation.find(filter, myOptions)); promises.push(models.ClaimObservation.find(filter, myOptions));

View File

@ -25,13 +25,17 @@
}, },
"created": { "created": {
"type": "date" "type": "date"
},
"userFk": {
"type": "number",
"required": true
} }
}, },
"relations": { "relations": {
"worker": { "user": {
"type": "belongsTo", "type": "belongsTo",
"model": "Worker", "model": "VnUser",
"foreignKey": "workerFk" "foreignKey": "userFk"
}, },
"claim": { "claim": {
"type": "belongsTo", "type": "belongsTo",

View File

@ -58,7 +58,7 @@ module.exports = Self => {
let stmt = new ParameterizedSQL( let stmt = new ParameterizedSQL(
`CREATE OR REPLACE TEMPORARY TABLE tmp.defaulters `CREATE OR REPLACE TEMPORARY TABLE tmp.defaulters
WITH clientObservations AS WITH clientObservations AS
(SELECT clientFk,text, created, workerFk (SELECT clientFk,text, created, userFk
FROM vn.clientObservation FROM vn.clientObservation
GROUP BY clientFk GROUP BY clientFk
ORDER BY created DESC ORDER BY created DESC
@ -87,7 +87,7 @@ module.exports = Self => {
JOIN payMethod pm ON pm.id = c.payMethodFk JOIN payMethod pm ON pm.id = c.payMethodFk
LEFT JOIN clientObservations co ON co.clientFk = c.id LEFT JOIN clientObservations co ON co.clientFk = c.id
LEFT JOIN account.user u ON u.id = c.salesPersonFk LEFT JOIN account.user u ON u.id = c.salesPersonFk
LEFT JOIN account.user uw ON uw.id = co.workerFk LEFT JOIN account.user uw ON uw.id = co.userFk
LEFT JOIN ( LEFT JOIN (
SELECT r1.started, r1.clientFk, r1.finished SELECT r1.started, r1.clientFk, r1.finished
FROM recovery r1 FROM recovery r1

View File

@ -30,7 +30,11 @@
"type": "belongsTo", "type": "belongsTo",
"model": "ObservationType", "model": "ObservationType",
"foreignKey": "observationTypeFk" "foreignKey": "observationTypeFk"
} },
"user": {
"type": "belongsTo",
"model": "VnUser",
"foreignKey": "userFk"
}
} }
} }

View File

@ -6,16 +6,4 @@ module.exports = function(Self) {
Self.validate('observationTypeFk', function(err) { Self.validate('observationTypeFk', function(err) {
if (!this.observationTypeFk) err(); if (!this.observationTypeFk) err();
}, {message: 'type cannot be blank'}); }, {message: 'type cannot be blank'});
Self.observe('before save', function(ctx, next) {
ctx.instance.created = Date();
let token = ctx.options.accessToken;
let userId = token && token.userId;
Self.app.models.Worker.findOne({where: {id: userId}}, (err, user) => {
if (err) return next(err);
ctx.instance.workerFk = user.id;
next();
});
});
}; };

View File

@ -19,6 +19,9 @@
"clientFk": { "clientFk": {
"type": "number" "type": "number"
}, },
"userFk": {
"type": "number"
},
"text": { "text": {
"type": "string", "type": "string",
"description": "Text" "description": "Text"
@ -33,33 +36,15 @@
} }
}, },
"relations": { "relations": {
"worker": { "user": {
"type": "belongsTo", "type": "belongsTo",
"model": "Worker", "model": "VnUser",
"foreignKey": "workerFk" "foreignKey": "userFk"
}, },
"client": { "client": {
"type": "belongsTo", "type": "belongsTo",
"model": "Client", "model": "Client",
"foreignKey": "clientFk" "foreignKey": "clientFk"
} }
},
"scope": {
"include": {
"relation": "worker",
"scope": {
"fields": [
"id"
],
"include": {
"relation": "user",
"scope": {
"fields": [
"name"
]
}
}
}
}
} }
} }

View File

@ -31,6 +31,11 @@
"model": "ObservationType", "model": "ObservationType",
"foreignKey": "observationTypeFk", "foreignKey": "observationTypeFk",
"required": true "required": true
} },
"user": {
"type": "belongsTo",
"model": "VnUser",
"foreignKey": "userFk"
}
} }
} }

View File

@ -31,6 +31,11 @@
"model": "ObservationType", "model": "ObservationType",
"foreignKey": "observationTypeFk", "foreignKey": "observationTypeFk",
"required": true "required": true
},
"user": {
"type": "belongsTo",
"model": "VnUser",
"foreignKey": "userFk"
} }
} }
} }

View File

@ -2,11 +2,4 @@ module.exports = function(Self) {
Self.validatesPresenceOf('text', { Self.validatesPresenceOf('text', {
message: 'Description cannot be blank' message: 'Description cannot be blank'
}); });
Self.observe('before save', async function(ctx) {
ctx.instance.created = new Date();
let token = ctx.options.accessToken;
let userId = token && token.userId;
ctx.instance.userFk = userId;
});
}; };

View File

@ -1,6 +1,9 @@
{ {
"name": "WorkerObservation", "name": "WorkerObservation",
"base": "VnModel", "base": "VnModel",
"mixins": {
"Loggable": true
},
"options": { "options": {
"mysql": { "mysql": {
"table": "workerObservation" "table": "workerObservation"
@ -32,7 +35,7 @@
}, },
"user":{ "user":{
"type": "belongsTo", "type": "belongsTo",
"model": "Account", "model": "VnUser",
"foreignKey": "userFk" "foreignKey": "userFk"
} }
} }