salix/modules/worker/back/models/locker.js

22 lines
660 B
JavaScript
Raw Normal View History

2024-05-10 11:04:12 +00:00
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);
}
}
});
};