This commit is contained in:
pqcqaq 2024-10-16 19:53:45 +08:00
parent 7b20c963d0
commit 08e698f996
2 changed files with 39 additions and 2 deletions

View File

@ -285,7 +285,7 @@ function outputContext(depGraph, sourceFile, printer, filename) {
const { statements } = sourceFile; const { statements } = sourceFile;
const isBackend = filename.includes('BackendRuntimeContext'); const isBackend = filename.includes('BackendRuntimeContext');
const statements2 = [ 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 ...statements
]; ];
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile); const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);

View File

@ -361,5 +361,42 @@ exports.logTriggers = [
}, {}); }, {});
return (result.oper?.remove || 0) + (result2.log?.remove || 0); 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;
}
},
]; ];