platfrom entityId
This commit is contained in:
parent
137276ec66
commit
17689ba1cf
|
|
@ -10,7 +10,7 @@ export declare function signatureJsSDK<ED extends EntityDict, Cxt extends Backen
|
|||
url: string;
|
||||
env: WebEnv;
|
||||
}, context: Cxt): Promise<{
|
||||
signature: any;
|
||||
signature: string;
|
||||
noncestr: string;
|
||||
timestamp: number;
|
||||
appId: string;
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ var Exception_2 = require("oak-domain/lib/types/Exception");
|
|||
var constants_1 = require("../constants");
|
||||
var AsyncRowStore_1 = require("oak-domain/lib/store/AsyncRowStore");
|
||||
var uuid_1 = require("oak-domain/lib/utils/uuid");
|
||||
var projection_1 = require("../types/projection");
|
||||
var wechatQrCode_1 = require("../aspects/wechatQrCode");
|
||||
/**
|
||||
* general数据结构要求的后台上下文
|
||||
|
|
@ -51,7 +52,8 @@ var BackendRuntimeContext = /** @class */ (function (_super) {
|
|||
if (!(_g < _e.length)) return [3 /*break*/, 6];
|
||||
id = _e[_g];
|
||||
wechatQrCodeData = wechatQrCodeListObj[id];
|
||||
if (!(wechatQrCodeData.hasOwnProperty('buffer') && wechatQrCodeData.type === 'wechatMpWxaCode')) return [3 /*break*/, 5];
|
||||
if (!(wechatQrCodeData.hasOwnProperty('buffer') &&
|
||||
wechatQrCodeData.type === 'wechatMpWxaCode')) return [3 /*break*/, 5];
|
||||
return [4 /*yield*/, (0, wechatQrCode_1.getMpUnlimitWxaCode)(id, this)];
|
||||
case 4:
|
||||
buffer = _j.sent();
|
||||
|
|
@ -112,7 +114,7 @@ var BackendRuntimeContext = /** @class */ (function (_super) {
|
|||
role: {
|
||||
id: 1,
|
||||
name: 1,
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -129,7 +131,7 @@ var BackendRuntimeContext = /** @class */ (function (_super) {
|
|||
role: {
|
||||
id: 1,
|
||||
name: 1,
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -157,9 +159,13 @@ var BackendRuntimeContext = /** @class */ (function (_super) {
|
|||
}
|
||||
user = token.user, player = token.player;
|
||||
userRole$user = user.userRole$user;
|
||||
this.amIRoot = userRole$user.length > 0 && userRole$user.find(function (ele) { return ele.role.name === 'root'; });
|
||||
this.amIRoot =
|
||||
userRole$user.length > 0 &&
|
||||
userRole$user.find(function (ele) { return ele.role.name === 'root'; });
|
||||
userRole$player = player.userRole$user;
|
||||
this.amIReallyRoot = userRole$player.length > 0 && userRole$player.find(function (ele) { return ele.role.name === 'root'; });
|
||||
this.amIReallyRoot =
|
||||
userRole$player.length > 0 &&
|
||||
userRole$player.find(function (ele) { return ele.role.name === 'root'; });
|
||||
this.token = token;
|
||||
return [2 /*return*/];
|
||||
}
|
||||
|
|
@ -172,28 +178,7 @@ var BackendRuntimeContext = /** @class */ (function (_super) {
|
|||
return tslib_1.__generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, this.select('application', {
|
||||
data: {
|
||||
id: 1,
|
||||
name: 1,
|
||||
config: 1,
|
||||
type: 1,
|
||||
systemId: 1,
|
||||
style: 1,
|
||||
system: {
|
||||
id: 1,
|
||||
name: 1,
|
||||
config: 1,
|
||||
platformId: 1,
|
||||
style: 1,
|
||||
folder: 1,
|
||||
super: 1,
|
||||
platform: {
|
||||
id: 1,
|
||||
config: 1,
|
||||
style: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
data: projection_1.applicationProjection,
|
||||
filter: {
|
||||
id: appId,
|
||||
},
|
||||
|
|
@ -289,7 +274,8 @@ var BackendRuntimeContext = /** @class */ (function (_super) {
|
|||
}
|
||||
if (this.token) {
|
||||
var userState = this.token.user.userState;
|
||||
if (['disabled', 'merged'].includes(userState) && !this.isReallyRoot()) {
|
||||
if (['disabled', 'merged'].includes(userState) &&
|
||||
!this.isReallyRoot()) {
|
||||
throw new Exception_1.OakUserDisabledException();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { String, Int, Text } from "oak-domain/lib/types/DataType";
|
||||
import { String, Int, Float, Text } from "oak-domain/lib/types/DataType";
|
||||
import { Q_DateValue, Q_NumberValue, Q_StringValue, Q_EnumValue, NodeId, MakeFilter, ExprOp, ExpressionKey } from "oak-domain/lib/types/Demand";
|
||||
import { OneOf } from "oak-domain/lib/types/Polyfill";
|
||||
import * as SubQuery from "../_SubQuery";
|
||||
|
|
@ -20,7 +20,7 @@ export declare type OpSchema = EntityShape & {
|
|||
extra1?: Text | null;
|
||||
extension: String<16>;
|
||||
size?: Int<4> | null;
|
||||
sort?: Int<4> | null;
|
||||
sort?: Float<4, 2> | null;
|
||||
fileType?: String<128> | null;
|
||||
};
|
||||
export declare type OpAttr = keyof OpSchema;
|
||||
|
|
@ -38,7 +38,7 @@ export declare type Schema = EntityShape & {
|
|||
extra1?: Text | null;
|
||||
extension: String<16>;
|
||||
size?: Int<4> | null;
|
||||
sort?: Int<4> | null;
|
||||
sort?: Float<4, 2> | null;
|
||||
fileType?: String<128> | null;
|
||||
article?: Article.Schema;
|
||||
user?: User.Schema;
|
||||
|
|
|
|||
|
|
@ -83,10 +83,10 @@ exports.desc = {
|
|||
}
|
||||
},
|
||||
sort: {
|
||||
type: "int",
|
||||
type: "decimal",
|
||||
params: {
|
||||
width: 4,
|
||||
signed: true
|
||||
precision: 4,
|
||||
scale: 2
|
||||
}
|
||||
},
|
||||
fileType: {
|
||||
|
|
|
|||
|
|
@ -2,19 +2,27 @@ import { RuntimeContext } from './RuntimeContext';
|
|||
import { EntityDict } from '../general-app-domain';
|
||||
import { SerializedData } from './FrontendRuntimeContext';
|
||||
import assert from 'assert';
|
||||
import { OakTokenExpiredException, OakUserDisabledException } from '../types/Exception';
|
||||
import { OakException, OakUnloggedInException } from 'oak-domain/lib/types/Exception';
|
||||
import {
|
||||
OakTokenExpiredException,
|
||||
OakUserDisabledException,
|
||||
} from '../types/Exception';
|
||||
import {
|
||||
OakException,
|
||||
OakUnloggedInException,
|
||||
} from 'oak-domain/lib/types/Exception';
|
||||
import { ROOT_TOKEN_ID, ROOT_USER_ID } from '../constants';
|
||||
import { AsyncContext } from 'oak-domain/lib/store/AsyncRowStore';
|
||||
import { generateNewIdAsync } from 'oak-domain/lib/utils/uuid';
|
||||
import { SelectOpResult } from 'oak-domain/lib/types';
|
||||
import {
|
||||
getMpUnlimitWxaCode,
|
||||
} from '../aspects/wechatQrCode';
|
||||
import { applicationProjection } from '../types/projection';
|
||||
import { getMpUnlimitWxaCode } from '../aspects/wechatQrCode';
|
||||
/**
|
||||
* general数据结构要求的后台上下文
|
||||
*/
|
||||
export class BackendRuntimeContext<ED extends EntityDict> extends AsyncContext<ED> implements RuntimeContext {
|
||||
export class BackendRuntimeContext<ED extends EntityDict>
|
||||
extends AsyncContext<ED>
|
||||
implements RuntimeContext
|
||||
{
|
||||
protected application?: Partial<ED['application']['Schema']>;
|
||||
protected token?: Partial<ED['token']['Schema']>;
|
||||
protected amIRoot?: boolean;
|
||||
|
|
@ -32,23 +40,28 @@ export class BackendRuntimeContext<ED extends EntityDict> extends AsyncContext<E
|
|||
// todo 小程序码此时去微信服务器获得码数据
|
||||
const wechatQrCodeListObj = d[entity];
|
||||
for (const id in wechatQrCodeListObj) {
|
||||
const wechatQrCodeData = wechatQrCodeListObj[id] as Partial<EntityDict['wechatQrCode']['OpSchema']>;
|
||||
if (wechatQrCodeData.hasOwnProperty('buffer') && wechatQrCodeData.type === 'wechatMpWxaCode') {
|
||||
const buffer = await getMpUnlimitWxaCode<ED, keyof ED, BackendRuntimeContext<ED>>(
|
||||
id,
|
||||
this,
|
||||
);
|
||||
Object.assign(
|
||||
wechatQrCodeData, {
|
||||
const wechatQrCodeData = wechatQrCodeListObj[
|
||||
id
|
||||
] as Partial<
|
||||
EntityDict['wechatQrCode']['OpSchema']
|
||||
>;
|
||||
if (
|
||||
wechatQrCodeData.hasOwnProperty('buffer') &&
|
||||
wechatQrCodeData.type === 'wechatMpWxaCode'
|
||||
) {
|
||||
const buffer = await getMpUnlimitWxaCode<
|
||||
ED,
|
||||
keyof ED,
|
||||
BackendRuntimeContext<ED>
|
||||
>(id, this);
|
||||
Object.assign(wechatQrCodeData, {
|
||||
buffer,
|
||||
}
|
||||
)
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else if (['application', 'system', 'platform'].includes(entity)) {
|
||||
} else if (
|
||||
['application', 'system', 'platform'].includes(entity)
|
||||
) {
|
||||
// todo 删除掉config中的敏感返回信息
|
||||
}
|
||||
}
|
||||
|
|
@ -57,73 +70,83 @@ export class BackendRuntimeContext<ED extends EntityDict> extends AsyncContext<E
|
|||
}
|
||||
|
||||
async setTokenValue(tokenValue: string) {
|
||||
const result = await this.select('token', {
|
||||
data: {
|
||||
id: 1,
|
||||
userId: 1,
|
||||
playerId: 1,
|
||||
player: {
|
||||
const result = await this.select(
|
||||
'token',
|
||||
{
|
||||
data: {
|
||||
id: 1,
|
||||
userState: 1,
|
||||
userRole$user: {
|
||||
$entity: 'userRole',
|
||||
data: {
|
||||
id: 1,
|
||||
userId: 1,
|
||||
roleId: 1,
|
||||
role: {
|
||||
userId: 1,
|
||||
playerId: 1,
|
||||
player: {
|
||||
id: 1,
|
||||
userState: 1,
|
||||
userRole$user: {
|
||||
$entity: 'userRole',
|
||||
data: {
|
||||
id: 1,
|
||||
name: 1,
|
||||
}
|
||||
userId: 1,
|
||||
roleId: 1,
|
||||
role: {
|
||||
id: 1,
|
||||
name: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
ableState: 1,
|
||||
user: {
|
||||
id: 1,
|
||||
userState: 1,
|
||||
userRole$user: {
|
||||
$entity: 'userRole',
|
||||
data: {
|
||||
id: 1,
|
||||
userId: 1,
|
||||
roleId: 1,
|
||||
role: {
|
||||
id: 1,
|
||||
name: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
ableState: 1,
|
||||
user: {
|
||||
id: 1,
|
||||
userState: 1,
|
||||
userRole$user: {
|
||||
$entity: 'userRole',
|
||||
data: {
|
||||
id: 1,
|
||||
userId: 1,
|
||||
roleId: 1,
|
||||
role: {
|
||||
id: 1,
|
||||
name: 1,
|
||||
}
|
||||
},
|
||||
},
|
||||
filter: {
|
||||
id: tokenValue,
|
||||
},
|
||||
},
|
||||
filter: {
|
||||
id: tokenValue,
|
||||
},
|
||||
}, {
|
||||
dontCollect: true,
|
||||
blockTrigger: true,
|
||||
});
|
||||
{
|
||||
dontCollect: true,
|
||||
blockTrigger: true,
|
||||
}
|
||||
);
|
||||
if (result.length === 0) {
|
||||
console.log(`构建BackendRuntimeContext对应tokenValue「${tokenValue}找不到相关的user`);
|
||||
console.log(
|
||||
`构建BackendRuntimeContext对应tokenValue「${tokenValue}找不到相关的user`
|
||||
);
|
||||
// throw new OakTokenExpiredException();
|
||||
this.tokenException = new OakTokenExpiredException();
|
||||
return;
|
||||
}
|
||||
const token = result[0];
|
||||
if (token.ableState === 'disabled') {
|
||||
console.log(`构建BackendRuntimeContext对应tokenValue「${tokenValue}已经被disable`);
|
||||
console.log(
|
||||
`构建BackendRuntimeContext对应tokenValue「${tokenValue}已经被disable`
|
||||
);
|
||||
this.tokenException = new OakTokenExpiredException();
|
||||
return;
|
||||
}
|
||||
const { user, player } = token;
|
||||
const { userRole$user } = user!;
|
||||
this.amIRoot = (userRole$user as any).length > 0 && (userRole$user as any).find(
|
||||
(ele: any) => ele.role.name === 'root'
|
||||
);
|
||||
this.amIRoot =
|
||||
(userRole$user as any).length > 0 &&
|
||||
(userRole$user as any).find((ele: any) => ele.role.name === 'root');
|
||||
const { userRole$user: userRole$player } = player!;
|
||||
this.amIReallyRoot = (userRole$player as any).length > 0 && (userRole$player as any).find(
|
||||
(ele: any) => ele.role.name === 'root'
|
||||
);
|
||||
this.amIReallyRoot =
|
||||
(userRole$player as any).length > 0 &&
|
||||
(userRole$player as any).find(
|
||||
(ele: any) => ele.role.name === 'root'
|
||||
);
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
|
|
@ -131,28 +154,7 @@ export class BackendRuntimeContext<ED extends EntityDict> extends AsyncContext<E
|
|||
const result = await this.select(
|
||||
'application',
|
||||
{
|
||||
data: {
|
||||
id: 1,
|
||||
name: 1,
|
||||
config: 1,
|
||||
type: 1,
|
||||
systemId: 1,
|
||||
style: 1,
|
||||
system: {
|
||||
id: 1,
|
||||
name: 1,
|
||||
config: 1,
|
||||
platformId: 1,
|
||||
style: 1,
|
||||
folder: 1,
|
||||
super: 1,
|
||||
platform: {
|
||||
id: 1,
|
||||
config: 1,
|
||||
style: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
data: applicationProjection,
|
||||
filter: {
|
||||
id: appId,
|
||||
},
|
||||
|
|
@ -162,7 +164,10 @@ export class BackendRuntimeContext<ED extends EntityDict> extends AsyncContext<E
|
|||
blockTrigger: true,
|
||||
}
|
||||
);
|
||||
assert(result.length > 0, `构建BackendRuntimeContext对应appId「${appId}」找不到application`);
|
||||
assert(
|
||||
result.length > 0,
|
||||
`构建BackendRuntimeContext对应appId「${appId}」找不到application`
|
||||
);
|
||||
this.application = result[0];
|
||||
}
|
||||
|
||||
|
|
@ -182,13 +187,11 @@ export class BackendRuntimeContext<ED extends EntityDict> extends AsyncContext<E
|
|||
await Promise.all(promises);
|
||||
}
|
||||
await this.commit();
|
||||
}
|
||||
catch (err) {
|
||||
} catch (err) {
|
||||
await this.rollback();
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// 否则是后台模式,默认用root
|
||||
this.rootMode = true;
|
||||
}
|
||||
|
|
@ -228,7 +231,10 @@ export class BackendRuntimeContext<ED extends EntityDict> extends AsyncContext<E
|
|||
}
|
||||
if (this.token) {
|
||||
const { userState } = this.token.user!;
|
||||
if (['disabled', 'merged'].includes(userState as string) && !this.isReallyRoot()) {
|
||||
if (
|
||||
['disabled', 'merged'].includes(userState as string) &&
|
||||
!this.isReallyRoot()
|
||||
) {
|
||||
throw new OakUserDisabledException();
|
||||
}
|
||||
}
|
||||
|
|
@ -269,13 +275,17 @@ export class BackendRuntimeContext<ED extends EntityDict> extends AsyncContext<E
|
|||
}
|
||||
|
||||
async sendMessage(data: ED['message']['CreateSingle']['data']) {
|
||||
return this.operate('message', {
|
||||
id: await generateNewIdAsync(),
|
||||
action: 'create',
|
||||
data,
|
||||
}, {
|
||||
dontCollect: true,
|
||||
});
|
||||
return this.operate(
|
||||
'message',
|
||||
{
|
||||
id: await generateNewIdAsync(),
|
||||
action: 'create',
|
||||
data,
|
||||
},
|
||||
{
|
||||
dontCollect: true,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
allowUserUpdate(): boolean {
|
||||
|
|
@ -286,16 +296,18 @@ export class BackendRuntimeContext<ED extends EntityDict> extends AsyncContext<E
|
|||
if (userInfo) {
|
||||
const { userState } = userInfo!;
|
||||
if (userState === 'disabled') {
|
||||
throw new OakUserDisabledException('您的帐号已经被禁用,请联系客服');
|
||||
}
|
||||
else if (['shadow', 'merged'].includes(userState!)) {
|
||||
throw new OakTokenExpiredException('您的登录状态有异常,请重新登录 ');
|
||||
}
|
||||
else {
|
||||
throw new OakUserDisabledException(
|
||||
'您的帐号已经被禁用,请联系客服'
|
||||
);
|
||||
} else if (['shadow', 'merged'].includes(userState!)) {
|
||||
throw new OakTokenExpiredException(
|
||||
'您的登录状态有异常,请重新登录 '
|
||||
);
|
||||
} else {
|
||||
assert(userState === 'normal');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
throw new OakUnloggedInException('您尚未登录');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue