37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
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;
|