75 lines
2.8 KiB
JavaScript
75 lines
2.8 KiB
JavaScript
import { generateNewIdAsync } from 'oak-domain/lib/utils/uuid';
|
||
import assert from 'assert';
|
||
// 这里一定要注意两者的先后顺序,如果有注入更多的payEntity的话
|
||
import { accountEntities } from '../checkers/abstractChecker';
|
||
const triggers = [
|
||
...accountEntities.filter(ele => !!ele).map((entity) => [
|
||
{
|
||
name: `当${entity}的帐户生成时,则生成对应的withDrawAccount`,
|
||
entity,
|
||
action: 'create',
|
||
when: 'before',
|
||
fn: async ({ operation }) => {
|
||
const { data } = operation;
|
||
assert(!(data instanceof Array));
|
||
const data2 = data;
|
||
data2.withdrawChannel$entity = [
|
||
{
|
||
id: await generateNewIdAsync(),
|
||
action: 'create',
|
||
data: {
|
||
id: await generateNewIdAsync(),
|
||
enabled: !!data2.allowWithdrawTransfer,
|
||
systemId: data2.systemId,
|
||
}
|
||
}
|
||
];
|
||
return 1;
|
||
}
|
||
},
|
||
{
|
||
name: `当${entity}的allowWithdrawTransfer发生改变时,同时修改对应的withdrawChannel的enabled值`,
|
||
entity,
|
||
action: 'update',
|
||
when: 'before',
|
||
check(operation) {
|
||
return operation.data.hasOwnProperty('allowWithdrawTransfer');
|
||
},
|
||
fn: async ({ operation }) => {
|
||
const { data } = operation;
|
||
assert(!(data instanceof Array));
|
||
const data2 = data;
|
||
data2.withdrawChannel$entity = [
|
||
{
|
||
id: await generateNewIdAsync(),
|
||
action: data2.allowWithdrawTransfer ? 'enable' : 'disable',
|
||
data: {
|
||
enabled: !!data2.allowWithdrawTransfer,
|
||
}
|
||
}
|
||
];
|
||
return 1;
|
||
}
|
||
},
|
||
{
|
||
name: `当${entity}的帐户的allowWithdrawTransfer发生改变时,同时修改对应的withdrawChannel的enabled值`,
|
||
entity,
|
||
action: 'remove',
|
||
when: 'after',
|
||
fn: async ({ operation }, context) => {
|
||
const { filter } = operation;
|
||
await context.operate('withdrawChannel', {
|
||
id: await generateNewIdAsync(),
|
||
action: 'remove',
|
||
data: {},
|
||
filter: {
|
||
[entity]: filter,
|
||
}
|
||
}, { dontCollect: true });
|
||
return 1;
|
||
}
|
||
},
|
||
]).flat(),
|
||
];
|
||
export default triggers;
|