一些checker和trigger

This commit is contained in:
Xu Chang 2022-04-30 13:58:28 +08:00
parent 5427a35bda
commit ac7797ecce
9 changed files with 43 additions and 36 deletions

View File

@ -110,6 +110,7 @@ async function loginWechatMp({ code, env }, context) {
}, },
}, },
}); });
}
await rowStore.operate('token', { await rowStore.operate('token', {
action: 'create', action: 'create',
data: { data: {
@ -126,7 +127,6 @@ async function loginWechatMp({ code, env }, context) {
env env
} }
}, context); }, context);
}
return id; return id;
} }
else if (unionId) { else if (unionId) {

View File

@ -5,6 +5,7 @@ const types_1 = require("oak-domain/lib/types");
const check_1 = require("../utils/check"); const check_1 = require("../utils/check");
const checkers = [ const checkers = [
{ {
type: 'data',
action: 'create', action: 'create',
entity: 'address', entity: 'address',
checker: async ({ operation }) => { checker: async ({ operation }) => {

View File

@ -1,3 +1,5 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const action_1 = require("oak-domain/lib/actions/action");
; ;
const AbleActionDef = (0, action_1.makeAbleActionDef)('enabled');

0
lib/triggers/token.d.ts vendored Normal file
View File

1
lib/triggers/token.js Normal file
View File

@ -0,0 +1 @@
"use strict";

View File

@ -6,7 +6,7 @@ import WechatSDK from 'oak-wechat-sdk';
import { CreateOperationData as CreateToken, WechatMpEnv } from 'oak-app-domain/Token/Schema'; import { CreateOperationData as CreateToken, WechatMpEnv } from 'oak-app-domain/Token/Schema';
import { CreateOperationData as CreateWechatUser } from 'oak-app-domain/WechatUser/Schema'; import { CreateOperationData as CreateWechatUser } from 'oak-app-domain/WechatUser/Schema';
import { CreateOperationData as CreateUser } from 'oak-app-domain/User/Schema'; import { CreateOperationData as CreateUser } from 'oak-app-domain/User/Schema';
import { assign, eq } from 'lodash'; import { assign, isEqual } from 'lodash';
import { SelectRowShape } from 'oak-domain/lib/types'; import { SelectRowShape } from 'oak-domain/lib/types';
export async function loginMp<ED extends EntityDict, Cxt extends GeneralRuntimeContext<ED>>(params: { code: string }, context: Cxt): Promise<string> { export async function loginMp<ED extends EntityDict, Cxt extends GeneralRuntimeContext<ED>>(params: { code: string }, context: Cxt): Promise<string> {
@ -88,7 +88,7 @@ export async function loginWechatMp<ED extends EntityDict, Cxt extends GeneralRu
entityId: wechatUser2.id, entityId: wechatUser2.id,
}, },
}, context); }, context);
if (token && eq(token.env, env)) { if (token && isEqual(token.env, env)) {
await rowStore.operate('token', { await rowStore.operate('token', {
action: 'update', action: 'update',
data: { data: {
@ -128,6 +128,7 @@ export async function loginWechatMp<ED extends EntityDict, Cxt extends GeneralRu
}, },
}, },
}); });
}
await rowStore.operate('token', { await rowStore.operate('token', {
action: 'create', action: 'create',
@ -145,7 +146,6 @@ export async function loginWechatMp<ED extends EntityDict, Cxt extends GeneralRu
env env
} as CreateToken } as CreateToken
}, context); }, context);
}
return id; return id;
} }

View File

@ -6,6 +6,7 @@ import { GeneralRuntimeContext } from '../RuntimeContext';
const checkers: Checker<EntityDict, 'address', GeneralRuntimeContext<EntityDict>> [] = [ const checkers: Checker<EntityDict, 'address', GeneralRuntimeContext<EntityDict>> [] = [
{ {
type: 'data',
action: 'create', action: 'create',
entity: 'address', entity: 'address',
checker: async ({ operation }) => { checker: async ({ operation }) => {

View File

@ -1,7 +1,7 @@
import { String, Int, Datetime, Image, Boolean } from 'oak-domain/lib/types/DataType'; import { String, Int, Datetime, Image, Boolean } from 'oak-domain/lib/types/DataType';
import { Schema as User } from './User'; import { Schema as User } from './User';
import { Schema as Application } from './Application'; import { Schema as Application } from './Application';
import { AbleAction } from 'oak-domain/lib/actions/action'; import { AbleAction, makeAbleActionDef } from 'oak-domain/lib/actions/action';
import { EntityShape } from 'oak-domain/lib/types/Entity'; import { EntityShape } from 'oak-domain/lib/types/Entity';
// https://developers.weixin.qq.com/miniprogram/dev/api/base/system/wx.getSystemInfoSync.html // https://developers.weixin.qq.com/miniprogram/dev/api/base/system/wx.getSystemInfoSync.html
export type WechatMpEnv = { export type WechatMpEnv = {
@ -39,3 +39,5 @@ export interface Schema extends EntityShape {
}; };
type Action = AbleAction; type Action = AbleAction;
const AbleActionDef = makeAbleActionDef('enabled');

0
src/triggers/token.ts Normal file
View File