This commit is contained in:
parent
7b20c963d0
commit
08e698f996
|
|
@ -285,7 +285,7 @@ function outputContext(depGraph, sourceFile, printer, filename) {
|
|||
const { statements } = sourceFile;
|
||||
const isBackend = filename.includes('BackendRuntimeContext');
|
||||
const statements2 = [
|
||||
factory.createImportDeclaration(undefined, factory.createImportClause(false, factory.createIdentifier(isBackend ? "BaseBackendRuntimeContext" : "BaseFrontendRuntimeContext"), undefined), factory.createStringLiteral(`${root}/es/context/${isBackend ? 'BackendRuntimeContext' : 'FrontendRuntimeContext'}`), undefined),
|
||||
factory.createImportDeclaration(undefined, factory.createImportClause(false, factory.createIdentifier(isBackend ? "BaseBackendRuntimeContext" : "BaseFrontendRuntimeContext"), undefined), factory.createStringLiteral(`${root}/${isBackend ? 'lib' : 'es'}/context/${isBackend ? 'BackendRuntimeContext' : 'FrontendRuntimeContext'}`), undefined),
|
||||
...statements
|
||||
];
|
||||
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
||||
|
|
|
|||
|
|
@ -361,5 +361,42 @@ exports.logTriggers = [
|
|||
}, {});
|
||||
return (result.oper?.remove || 0) + (result2.log?.remove || 0);
|
||||
}
|
||||
}
|
||||
},
|
||||
// 在删除log时,解除与此log关联的oper
|
||||
{
|
||||
name: '当删除log时,解除与此log关联的oper',
|
||||
entity: 'log',
|
||||
action: 'remove',
|
||||
when: 'before',
|
||||
fn: async ({ operation }, context) => {
|
||||
const { filter } = operation;
|
||||
(0, assert_1.default)(filter);
|
||||
// 查询这次删除操作涉及到的所有log
|
||||
const logs = await context.select('log', {
|
||||
data: {
|
||||
id: 1,
|
||||
oper$log: {
|
||||
$entity: 'oper',
|
||||
data: {
|
||||
id: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
filter,
|
||||
}, {});
|
||||
const operIds = logs.flatMap(log => log.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;
|
||||
}
|
||||
},
|
||||
];
|
||||
|
|
|
|||
Loading…
Reference in New Issue