account trigger
This commit is contained in:
parent
960681a2e8
commit
4fe3e62dc1
|
|
@ -0,0 +1,5 @@
|
|||
import { EntityDict } from '../oak-app-domain/EntityDict';
|
||||
import { Trigger } from 'oak-domain/lib/types';
|
||||
import { BackendRuntimeContext } from '../context/BackendRuntimeContext';
|
||||
declare const triggers: Trigger<EntityDict, 'account', BackendRuntimeContext<EntityDict>>[];
|
||||
export default triggers;
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
import { assert } from 'oak-domain/lib/utils/assert';
|
||||
import { generateNewIdAsync } from 'oak-domain/lib/utils/uuid';
|
||||
const triggers = [
|
||||
// 目前先这样授予关系
|
||||
{
|
||||
name: '充值的时候,将用户赋予owner关系',
|
||||
entity: 'account',
|
||||
action: 'create',
|
||||
when: 'before',
|
||||
fn: async (event, context) => {
|
||||
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,
|
||||
},
|
||||
}, {});
|
||||
closeRootMode();
|
||||
return 1;
|
||||
},
|
||||
},
|
||||
];
|
||||
export default triggers;
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
import { EntityDict } from '../oak-app-domain/EntityDict';
|
||||
import { Trigger } from 'oak-domain/lib/types';
|
||||
import { BackendRuntimeContext } from '../context/BackendRuntimeContext';
|
||||
declare const triggers: Trigger<EntityDict, 'account', BackendRuntimeContext<EntityDict>>[];
|
||||
export default triggers;
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const assert_1 = require("oak-domain/lib/utils/assert");
|
||||
const uuid_1 = require("oak-domain/lib/utils/uuid");
|
||||
const triggers = [
|
||||
// 目前先这样授予关系
|
||||
{
|
||||
name: '充值的时候,将用户赋予owner关系',
|
||||
entity: 'account',
|
||||
action: 'create',
|
||||
when: 'before',
|
||||
fn: async (event, context) => {
|
||||
const { operation: { data, filter }, } = event;
|
||||
(0, assert_1.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 });
|
||||
(0, assert_1.assert)(relation);
|
||||
const closeRootMode = context.openRootMode();
|
||||
await context.operate('userRelation', {
|
||||
id: await (0, uuid_1.generateNewIdAsync)(),
|
||||
action: 'create',
|
||||
data: {
|
||||
id: await (0, uuid_1.generateNewIdAsync)(),
|
||||
relationId: relation.id,
|
||||
userId: context.getCurrentUserId(),
|
||||
entity: 'account',
|
||||
entityId: accountId,
|
||||
},
|
||||
}, {});
|
||||
closeRootMode();
|
||||
return 1;
|
||||
},
|
||||
},
|
||||
];
|
||||
exports.default = triggers;
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
import { EntityDict } from '../oak-app-domain/EntityDict';
|
||||
import { Trigger } from 'oak-domain/lib/types';
|
||||
import { BackendRuntimeContext } from '../context/BackendRuntimeContext';
|
||||
import { assert } from 'oak-domain/lib/utils/assert';
|
||||
import { generateNewIdAsync } from 'oak-domain/lib/utils/uuid';
|
||||
import { OakPreConditionUnsetException } from 'oak-domain/lib/types';
|
||||
import { RuntimeCxt } from '../types/RuntimeCxt';
|
||||
|
||||
const triggers: Trigger<
|
||||
EntityDict,
|
||||
'account',
|
||||
BackendRuntimeContext<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']['CreateSingle']['data'],
|
||||
},
|
||||
{}
|
||||
);
|
||||
closeRootMode();
|
||||
return 1;
|
||||
},
|
||||
},
|
||||
];
|
||||
export default triggers;
|
||||
|
|
@ -14,8 +14,11 @@ import sessionMessageTriggers from './sessionMessage';
|
|||
import wechatMenuTriggers from './wechatMenu';
|
||||
import wechatPublicTag from './wechatPublicTag';
|
||||
|
||||
import accountTriggers from './account';
|
||||
|
||||
|
||||
export default [
|
||||
...accountTriggers,
|
||||
...applicationTriggers,
|
||||
...addressTriggers,
|
||||
...userTriggers,
|
||||
|
|
|
|||
Loading…
Reference in New Issue