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

55 lines
1.8 KiB
JavaScript
Raw Permalink 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.

export {};
/* const triggers: Trigger<
EntityDict,
'account',
BRC<EntityDict>
>[] = [
// 目前先这样授予关系
{
name: '充值的时候将用户赋予owner关系',
entity: 'account',
action: 'create',
when: 'before',
fn: async (event: any, context: any) => {
const {
operation: { data, filter },
} = event;
assert(!(data instanceof Array));
const accountId = data.id!;
const [relation] = await context.select('relation', {
data: {
id: 1,
},
filter: {
name: 'owner',
entity: 'account',
entityId: {
$exists: false,
}
}
}, { dontCollect: true });
assert(relation);
const closeRootMode = context.openRootMode();
await context.operate(
'userRelation',
{
id: await generateNewIdAsync(),
action: 'create',
data: {
id: await generateNewIdAsync(),
relationId: relation.id,
userId: context.getCurrentUserId(),
entity: 'account',
entityId: accountId!,
} as EntityDict['userRelation']['CreateOperationData'],
},
{}
);
closeRootMode();
return 1;
},
},
];
export default triggers; */