oak-pay-business/lib/triggers/abstract.js

78 lines
3.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const uuid_1 = require("oak-domain/lib/utils/uuid");
const assert_1 = tslib_1.__importDefault(require("assert"));
// 这里一定要注意两者的先后顺序如果有注入更多的payEntity的话
const abstractChecker_1 = require("../checkers/abstractChecker");
const triggers = [
...abstractChecker_1.accountEntities.filter(ele => !!ele).map((entity) => [
{
name: `${entity}的帐户生成时则生成对应的withDrawAccount`,
entity,
action: 'create',
when: 'before',
fn: async ({ operation }) => {
const { data } = operation;
(0, assert_1.default)(!(data instanceof Array));
const data2 = data;
data2.withdrawChannel$entity = [
{
id: await (0, uuid_1.generateNewIdAsync)(),
action: 'create',
data: {
id: await (0, uuid_1.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;
(0, assert_1.default)(!(data instanceof Array));
const data2 = data;
data2.withdrawChannel$entity = [
{
id: await (0, uuid_1.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 (0, uuid_1.generateNewIdAsync)(),
action: 'remove',
data: {},
filter: {
[entity]: filter,
}
}, { dontCollect: true });
return 1;
}
},
]).flat(),
];
exports.default = triggers;