feat: refs #5919 hook

This commit is contained in:
Jorge Penadés 2024-05-10 13:04:12 +02:00
parent 4e7d0e6469
commit af11bb8663
3 changed files with 24 additions and 1 deletions

View File

@ -0,0 +1,2 @@
ALTER TABLE vn.workerLog
MODIFY COLUMN changedModel enum('Worker','Calendar','WorkerTimeControlMail','Business','WorkerDms','WorkerTimeControl', 'Locker') NOT NULL DEFAULT 'Worker';

View File

@ -0,0 +1,21 @@
module.exports = Self => {
Self.observe('before save', async ctx => {
const models = Self.app.models;
const changes = ctx.data || ctx.instance;
const instance = ctx.currentInstance;
const workerFk = changes?.workerFk || instance?.workerFk;
if (workerFk) {
const locker = await models.Locker.findOne({
where: {workerFk}
}, ctx.options);
if (locker) {
await Self.rawSql(
'UPDATE locker SET workerFk = NULL where workerFk = ?',
[workerFk],
ctx.options);
}
}
});
};

View File

@ -96,7 +96,7 @@
"foreignKey": "workerFk" "foreignKey": "workerFk"
}, },
"locker": { "locker": {
"type": "hasOne", "type": "hasMany",
"model": "Locker", "model": "Locker",
"foreignKey": "workerFk" "foreignKey": "workerFk"
} }