oak-general-business/es/triggers/system.js

46 lines
1.4 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 { desc } from '../oak-app-domain/Passport/Storage';
import { assert } from 'oak-domain/lib/utils/assert';
const { attributes: { type: passportType } } = desc;
const triggers = [
{
name: '添加system时添加相应的passport',
entity: 'system',
action: 'create',
when: 'before',
fn: async ({ operation }) => {
const { data } = operation;
assert(!(data instanceof Array));
data.passport$system = await Promise.all(passportType.enumeration.map(async (type) => ({
id: await generateNewIdAsync(),
action: 'create',
data: {
id: await generateNewIdAsync(),
type,
enabled: false,
}
})));
return 1;
}
},
{
name: '当system删除前删除相关的passports',
entity: 'system',
action: 'remove',
when: 'before',
fn: async ({ operation }, context, option) => {
const { filter } = operation;
await context.operate('passport', {
id: await generateNewIdAsync(),
action: 'remove',
data: {},
filter: {
system: filter,
},
}, option);
return 1;
},
},
];
export default triggers;