新增删除等action的checkers

This commit is contained in:
pqcqaq 2024-10-16 20:02:54 +08:00
parent 6ab46415b4
commit b0463e73b7
1 changed files with 63 additions and 0 deletions

View File

@ -1,6 +1,9 @@
import { EntityDict } from '@oak-app-domain';
import { Checker } from 'oak-domain/lib/types';
import { RuntimeCxt } from '../types/RuntimeCxt';
import { generateNewId } from 'oak-domain/lib/utils/uuid';
import assert from 'assert';
import { pipeline } from 'oak-domain/lib/utils/executor';
const checkers: Checker<EntityDict, 'essay', RuntimeCxt>[] = [
{
@ -29,6 +32,66 @@ const checkers: Checker<EntityDict, 'essay', RuntimeCxt>[] = [
isTop: true,
},
},
// 在删除essay的时候同步删除extraFile和essayLabels还有log
// 注意在checker中为非异步环境这点与trigger不同
{
entity: 'essay',
action: 'remove',
type: 'logical',
checker: (operation, context, option) => {
const { filter } = operation;
assert(filter && typeof filter.id === 'string');
// 在pipline中可以传入一系列需要执行的context操作
// 上一个操作的执行结果会被传递到下一个函数的入参中
return pipeline(
() => {
// 删除相关的extraFile
return context.operate(
'extraFile',
{
action: 'remove',
id: generateNewId(),
data: {},
filter: {
essay: filter,
},
},
option
);
},
() => {
// 删除相关的essayLabels
return context.operate(
'essayLabels',
{
action: 'remove',
id: generateNewId(),
data: {},
filter: {
essay: filter,
},
},
option
);
},
() => {
// 删除相关的log
return context.operate(
'log',
{
action: 'remove',
id: generateNewId(),
data: {},
filter: {
essay: filter,
},
},
option
);
}
);
},
},
];
export default checkers;