weChatQrCode的数据结构更新

This commit is contained in:
Xu Chang 2022-05-30 11:27:48 +08:00
parent 1073522993
commit b0ff174e44
6 changed files with 57 additions and 24 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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<Schema>[] = [

View File

@ -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<EntityDict, 'userEntityGrant', GeneralRuntimeContext<EntityDict>>[] = [
@ -16,6 +16,8 @@ const triggers: Trigger<EntityDict, 'userEntityGrant', GeneralRuntimeContext<Ent
fn: async ({ operation }, context, params) => {
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<EntityDict, 'userEntityGrant', GeneralRuntimeContext<Ent
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) {
const d = {};
result.forEach(
(ele) => 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('授权不存在一对多的情况')

View File

@ -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
}

View File

@ -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<EntityDict['userEntityGrant']['OpSchema']>;
const { id } = data;
this.navigateTo({
url: '../detail/index',
oakId: id,
});
}
catch (error) {
console.log(error);
if (error instanceof OakRowInconsistencyException) {
const data = error.getData();
if ((<OakException>error).constructor.name === OakCongruentRowExists.name) {
// 这里由于编译的问题用instanceof会不通过检查
const data = (<OakCongruentRowExists<EntityDict, 'userEntityGrant'>>error).getData();
console.log(data);
this.navigateTo({
url: '../detail/index',
oakId: data.id,
});
}
}
}