diff --git a/lib/entities/WechatQrCode.d.ts b/lib/entities/WechatQrCode.d.ts index 535e2b85b..567ab3a98 100644 --- a/lib/entities/WechatQrCode.d.ts +++ b/lib/entities/WechatQrCode.d.ts @@ -1,5 +1,6 @@ import { String, Text, Datetime, Boolean } from 'oak-domain/lib/types/DataType'; import { EntityShape } from 'oak-domain/lib/types/Entity'; +import { Schema as Application } from './Application'; export interface Schema extends EntityShape { entity: String<32>; entityId: String<64>; @@ -9,6 +10,9 @@ export interface Schema extends EntityShape { autoExtend: Boolean; sceneStr?: Text; ticket?: Text; - url: String<64>; + url?: String<64>; isPermanent: Boolean; + buffer?: Text; + application: Application; + props?: Object; } diff --git a/lib/triggers/userEntityGrant.js b/lib/triggers/userEntityGrant.js index aa41a7ace..d328ff277 100644 --- a/lib/triggers/userEntityGrant.js +++ b/lib/triggers/userEntityGrant.js @@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); +const lodash_1 = require("lodash"); const types_1 = require("oak-domain/lib/types"); const assert_1 = __importDefault(require("assert")); const triggers = [ @@ -14,6 +15,8 @@ const triggers = [ fn: async ({ operation }, context, params) => { const { data, filter } = operation; const fn = async (userEntityGrantData) => { + const { userId } = (await context.getToken()); + (0, assert_1.default)(userId); const { action, entity, entityId, relation } = userEntityGrantData; const { result } = await context.rowStore.select('userEntityGrant', { data: { @@ -22,26 +25,32 @@ const triggers = [ entity: 1, entityId: 1, relation: 1, + iState: 1, + granterId: 1, }, filter: { iState: 'init', action, entity, entityId, + granterId: userId, relation, }, indexFrom: 0, count: 1, }, context, params); if (result.length) { - throw new types_1.OakRowInconsistencyException(result[0], '该userEntityGrant未过期'); + throw new types_1.OakCongruentRowExists(result[0], '有可重用的userEntityGrant'); } + (0, lodash_1.assign)(userEntityGrantData, { + granterId: userId, + }); }; if (data instanceof Array) { (0, assert_1.default)('授权不存在一对多的情况'); } else { - fn(data); + await fn(data); } return 0; } diff --git a/src/entities/WechatQrCode.ts b/src/entities/WechatQrCode.ts index 8e9fb53fc..1c4bee3bc 100644 --- a/src/entities/WechatQrCode.ts +++ b/src/entities/WechatQrCode.ts @@ -1,6 +1,7 @@ import { String, Text, Datetime, Boolean } from 'oak-domain/lib/types/DataType'; import { EntityShape } from 'oak-domain/lib/types/Entity'; import { Index } from 'oak-domain/lib/types/Storage'; +import { Schema as Application } from './Application'; export interface Schema extends EntityShape { entity: String<32>; @@ -11,8 +12,11 @@ export interface Schema extends EntityShape { autoExtend: Boolean; sceneStr?: Text; ticket?: Text; - url: String<64>; + url?: String<64>; isPermanent: Boolean; //是否永久码 + buffer?: Text; // 若没有url,使用buffer存储生成的小程序码数据(base64) + application: Application; + props?: Object; } const indexes: Index[] = [ diff --git a/src/triggers/userEntityGrant.ts b/src/triggers/userEntityGrant.ts index b4600ffa2..f0767e543 100644 --- a/src/triggers/userEntityGrant.ts +++ b/src/triggers/userEntityGrant.ts @@ -4,7 +4,7 @@ import { GeneralRuntimeContext } from '../RuntimeContext'; import { CreateOperationData as CreateUserEntityGrantData } from 'oak-app-domain/UserEntityGrant/Schema'; import { assign, keys } from 'lodash'; -import { OakRowInconsistencyException } from 'oak-domain/lib/types'; +import { OakCongruentRowExists } from 'oak-domain/lib/types'; import assert from 'assert'; const triggers: Trigger>[] = [ @@ -16,6 +16,8 @@ const triggers: Trigger { const { data, filter } = operation; const fn = async (userEntityGrantData: CreateUserEntityGrantData) => { + const { userId } = (await context.getToken())!; + assert(userId); const { action, entity, entityId, relation} = userEntityGrantData; const { result } = await context.rowStore.select('userEntityGrant', { data: { @@ -24,31 +26,27 @@ const triggers: Trigger assign(d, { - [ele.id]: ele, - }) - ); - throw new OakRowInconsistencyException({ - a: 's', - d: { - userEntityGrant: d, - } - }, '有可重用的userEntityGrant'); + throw new OakCongruentRowExists(result[0] as any, '有可重用的userEntityGrant'); } + + assign(userEntityGrantData, { + granterId: userId, + }); } if (data instanceof Array) { assert('授权不存在一对多的情况') diff --git a/wechatMp/pages/userEntityGrant/detail/index.ts b/wechatMp/pages/userEntityGrant/detail/index.ts index 81e55b367..e1e2cc147 100644 --- a/wechatMp/pages/userEntityGrant/detail/index.ts +++ b/wechatMp/pages/userEntityGrant/detail/index.ts @@ -3,17 +3,19 @@ OakPage({ path: 'userEntityGrant:detail', entity: 'userEntityGrant', projection: { + id: 1, entity: 1, entityId: 1, relation: 1, action: 1, remark: 1, uuid: 1, - granter: 1, - grantee: 1, + granterId: 1, + granteeId: 1, wechatQrCode$entity: { $entity: 'wechatQrCode', data: { + id: 1, entity: 1, entityId: 1, type: 1,//类型 @@ -41,7 +43,7 @@ OakPage({ data: { }, lifetimes: { - ready(options) { + ready() { if (!this.data.wechatQrCode$entity[0] || this.data.wechatQrCode$entity[0].expiresAt) { //请求创建wechatQrcode } diff --git a/wechatMp/pages/userEntityGrant/upsert/index.ts b/wechatMp/pages/userEntityGrant/upsert/index.ts index c4798fc5b..15d956e9d 100644 --- a/wechatMp/pages/userEntityGrant/upsert/index.ts +++ b/wechatMp/pages/userEntityGrant/upsert/index.ts @@ -1,4 +1,5 @@ -import { OakRowInconsistencyException } from "oak-domain/lib/types"; +import { EntityDict } from "oak-app-domain"; +import { DeduceCreateOperation, DeduceCreateSingleOperation, OakException, OakCongruentRowExists } from "oak-domain/lib/types"; OakPage({ path: 'userEntityGrant:upsert', @@ -45,13 +46,28 @@ OakPage({ try { const result = await this.execute( this.data.oakId ? 'update' : 'create', - [OakRowInconsistencyException] + [OakCongruentRowExists.name] ); + + console.log(result); + const { data } = result as DeduceCreateSingleOperation; + const { id } = data; + + this.navigateTo({ + url: '../detail/index', + oakId: id, + }); } catch (error) { console.log(error); - if (error instanceof OakRowInconsistencyException) { - const data = error.getData(); + if ((error).constructor.name === OakCongruentRowExists.name) { + // 这里由于编译的问题,用instanceof会不通过检查 + const data = (>error).getData(); + console.log(data); + this.navigateTo({ + url: '../detail/index', + oakId: data.id, + }); } } }