oak-pay-business/es/triggers/sysAccountOper.js

37 lines
1.1 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.

import { generateNewIdAsync } from 'oak-domain/lib/utils/uuid';
import assert from 'assert';
const triggers = [
{
name: '当生成sysAccountOper时修改对应的系统帐户中的值',
entity: 'sysAccountOper',
action: 'create',
when: 'after',
fn: async ({ operation }, context, option) => {
const { id, data } = operation;
assert(!(data instanceof Array));
const { entity, entityId, delta, type } = data;
const [row] = await context.select(entity, {
data: {
id: 1,
price: 1,
},
filter: {
id: entityId,
},
}, { forUpdate: true });
await context.operate(entity, {
id: await generateNewIdAsync(),
action: type,
data: {
price: row.price + delta,
},
filter: {
id: entityId,
},
}, {});
return 1;
},
},
];
export default triggers;