feat: refs #5919 hook
This commit is contained in:
parent
4e7d0e6469
commit
af11bb8663
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE vn.workerLog
|
||||||
|
MODIFY COLUMN changedModel enum('Worker','Calendar','WorkerTimeControlMail','Business','WorkerDms','WorkerTimeControl', 'Locker') NOT NULL DEFAULT 'Worker';
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
|
@ -96,7 +96,7 @@
|
||||||
"foreignKey": "workerFk"
|
"foreignKey": "workerFk"
|
||||||
},
|
},
|
||||||
"locker": {
|
"locker": {
|
||||||
"type": "hasOne",
|
"type": "hasMany",
|
||||||
"model": "Locker",
|
"model": "Locker",
|
||||||
"foreignKey": "workerFk"
|
"foreignKey": "workerFk"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue