新增删除等action的checkers
This commit is contained in:
parent
6ab46415b4
commit
b0463e73b7
|
|
@ -1,6 +1,9 @@
|
||||||
import { EntityDict } from '@oak-app-domain';
|
import { EntityDict } from '@oak-app-domain';
|
||||||
import { Checker } from 'oak-domain/lib/types';
|
import { Checker } from 'oak-domain/lib/types';
|
||||||
import { RuntimeCxt } from '../types/RuntimeCxt';
|
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>[] = [
|
const checkers: Checker<EntityDict, 'essay', RuntimeCxt>[] = [
|
||||||
{
|
{
|
||||||
|
|
@ -29,6 +32,66 @@ const checkers: Checker<EntityDict, 'essay', RuntimeCxt>[] = [
|
||||||
isTop: true,
|
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;
|
export default checkers;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue