backendContext增加了later模式
This commit is contained in:
parent
0992b961a5
commit
3e76b9f9e9
|
|
@ -23,8 +23,7 @@ import { cloneDeep } from 'oak-domain/lib/utils/lodash';
|
||||||
*/
|
*/
|
||||||
export abstract class BackendRuntimeContext<ED extends EntityDict & BaseEntityDict>
|
export abstract class BackendRuntimeContext<ED extends EntityDict & BaseEntityDict>
|
||||||
extends BRC<ED>
|
extends BRC<ED>
|
||||||
implements RuntimeContext
|
implements RuntimeContext {
|
||||||
{
|
|
||||||
protected application?: Partial<ED['application']['Schema']>;
|
protected application?: Partial<ED['application']['Schema']>;
|
||||||
protected token?: Partial<ED['token']['Schema']>;
|
protected token?: Partial<ED['token']['Schema']>;
|
||||||
protected amIRoot?: boolean;
|
protected amIRoot?: boolean;
|
||||||
|
|
@ -70,7 +69,8 @@ export abstract class BackendRuntimeContext<ED extends EntityDict & BaseEntityDi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async setTokenValue(tokenValue: string, later?: boolean) {
|
async setTokenValue(tokenValue: string, later?: boolean, userId?: string) {
|
||||||
|
if (!later || !userId) {
|
||||||
const result = await this.select(
|
const result = await this.select(
|
||||||
'token',
|
'token',
|
||||||
{
|
{
|
||||||
|
|
@ -101,7 +101,9 @@ export abstract class BackendRuntimeContext<ED extends EntityDict & BaseEntityDi
|
||||||
console.log(
|
console.log(
|
||||||
`构建BackendRuntimeContext对应tokenValue「${tokenValue}找不到相关的user`
|
`构建BackendRuntimeContext对应tokenValue「${tokenValue}找不到相关的user`
|
||||||
);
|
);
|
||||||
|
if (!later) {
|
||||||
throw new OakTokenExpiredException();
|
throw new OakTokenExpiredException();
|
||||||
|
}
|
||||||
// this.tokenException = new OakTokenExpiredException();
|
// this.tokenException = new OakTokenExpiredException();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -119,6 +121,18 @@ export abstract class BackendRuntimeContext<ED extends EntityDict & BaseEntityDi
|
||||||
this.amIReallyRoot = player?.isRoot!;
|
this.amIReallyRoot = player?.isRoot!;
|
||||||
this.token = token;
|
this.token = token;
|
||||||
}
|
}
|
||||||
|
const [user] = await this.select('user', {
|
||||||
|
data: {
|
||||||
|
id: 1,
|
||||||
|
isRoot: 1,
|
||||||
|
},
|
||||||
|
filter: { id: userId },
|
||||||
|
}, { dontCollect: true });
|
||||||
|
assert(user, '初始化context时有userId但查询不到user');
|
||||||
|
this.amIRoot = user.isRoot!;
|
||||||
|
this.amIReallyRoot = user.isRoot!;
|
||||||
|
this.userId = userId;
|
||||||
|
}
|
||||||
|
|
||||||
async setApplication(appId: string) {
|
async setApplication(appId: string) {
|
||||||
const result = await this.select(
|
const result = await this.select(
|
||||||
|
|
@ -146,13 +160,13 @@ export abstract class BackendRuntimeContext<ED extends EntityDict & BaseEntityDi
|
||||||
if (data) {
|
if (data) {
|
||||||
const closeRootMode = this.openRootMode();
|
const closeRootMode = this.openRootMode();
|
||||||
try {
|
try {
|
||||||
const { a: appId, t: tokenValue, rm } = data;
|
const { a: appId, t: tokenValue, rm, userId } = data;
|
||||||
const promises: Promise<void>[] = [];
|
const promises: Promise<void>[] = [];
|
||||||
if (appId) {
|
if (appId) {
|
||||||
promises.push(this.setApplication(appId));
|
promises.push(this.setApplication(appId));
|
||||||
}
|
}
|
||||||
if (tokenValue) {
|
if (tokenValue) {
|
||||||
promises.push(this.setTokenValue(tokenValue, later));
|
promises.push(this.setTokenValue(tokenValue, later, userId));
|
||||||
}
|
}
|
||||||
if (promises.length > 0) {
|
if (promises.length > 0) {
|
||||||
await Promise.all(promises);
|
await Promise.all(promises);
|
||||||
|
|
@ -236,6 +250,7 @@ export abstract class BackendRuntimeContext<ED extends EntityDict & BaseEntityDi
|
||||||
a: this.application?.id,
|
a: this.application?.id,
|
||||||
t: this.token?.value,
|
t: this.token?.value,
|
||||||
rm: this.rootMode,
|
rm: this.rootMode,
|
||||||
|
userId: this.getCurrentUserId(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ export type AspectDict<
|
||||||
export interface SerializedData extends Fsd {
|
export interface SerializedData extends Fsd {
|
||||||
a?: string;
|
a?: string;
|
||||||
t?: string;
|
t?: string;
|
||||||
|
userId?: string; // 后台专用
|
||||||
rm?: boolean;
|
rm?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue