在删除log时,删除与此log关联的oper
This commit is contained in:
parent
9ac752687a
commit
e3881534b9
|
|
@ -378,9 +378,9 @@ export const logTriggers: Trigger<EntityDict & BaseEntityDict, 'log', AsyncConte
|
||||||
return (result.oper?.remove || 0) + (result2.log?.remove || 0);
|
return (result.oper?.remove || 0) + (result2.log?.remove || 0);
|
||||||
}
|
}
|
||||||
} as CreateTriggerInTxn<EntityDict & BaseEntityDict, 'log', AsyncContext<EntityDict & BaseEntityDict>>,
|
} as CreateTriggerInTxn<EntityDict & BaseEntityDict, 'log', AsyncContext<EntityDict & BaseEntityDict>>,
|
||||||
// 在删除log时,解除与此log关联的oper
|
// 在删除log时,删除与此log关联的oper
|
||||||
{
|
{
|
||||||
name: '当删除log时,解除与此log关联的oper',
|
name: '当删除log时,删除与此log关联的oper',
|
||||||
entity: 'log',
|
entity: 'log',
|
||||||
action: 'remove',
|
action: 'remove',
|
||||||
when: 'before',
|
when: 'before',
|
||||||
|
|
@ -388,33 +388,15 @@ export const logTriggers: Trigger<EntityDict & BaseEntityDict, 'log', AsyncConte
|
||||||
const { filter } = operation;
|
const { filter } = operation;
|
||||||
assert(filter);
|
assert(filter);
|
||||||
// 查询这次删除操作涉及到的所有log
|
// 查询这次删除操作涉及到的所有log
|
||||||
const logs = await context.select('log', {
|
const result = await context.operate('oper', {
|
||||||
data: {
|
id: "dummy",
|
||||||
id: 1,
|
action: 'remove',
|
||||||
oper$log: {
|
data: {},
|
||||||
$entity: 'oper',
|
filter: {
|
||||||
data: {
|
log: filter,
|
||||||
id: 1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
filter,
|
|
||||||
}, {});
|
|
||||||
|
|
||||||
const operIds = logs.flatMap(log => (log as BaseEntityDict['log']['Schema']).oper$log!.map(oper => oper.id));
|
|
||||||
let result = 0;
|
|
||||||
for (const operId of operIds) {
|
|
||||||
const result2 = await context.operate('oper', {
|
|
||||||
id: operId,
|
|
||||||
action: 'update',
|
|
||||||
data: {
|
|
||||||
logId: null,
|
|
||||||
},
|
|
||||||
}, {});
|
|
||||||
|
|
||||||
result += result2.oper?.update || 0;
|
|
||||||
}
|
}
|
||||||
return result;
|
}, {});
|
||||||
|
return result.oper?.remove || 0;
|
||||||
}
|
}
|
||||||
} as RemoveTriggerInTxn<EntityDict & BaseEntityDict, 'log', AsyncContext<EntityDict & BaseEntityDict>>,
|
} as RemoveTriggerInTxn<EntityDict & BaseEntityDict, 'log', AsyncContext<EntityDict & BaseEntityDict>>,
|
||||||
];
|
];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue