feat: wip server folder structure (#4573)
* feat: wip server folder structure * fix: merge * fix: wrong merge * fix: remove unused file * fix: comment * fix: lint * fix: merge * fix: remove console.log * fix: metadata graphql arguments broken
This commit is contained in:
@ -0,0 +1,38 @@
|
||||
import {
|
||||
HostComponentInfo,
|
||||
ContextId,
|
||||
ContextIdFactory,
|
||||
ContextIdStrategy,
|
||||
} from '@nestjs/core';
|
||||
|
||||
import { jwtDecode } from 'jwt-decode';
|
||||
import { Request } from 'express';
|
||||
|
||||
import { JwtPayload } from 'src/engine/core-modules/auth/strategies/jwt.auth.strategy';
|
||||
|
||||
const workspaces = new Map<string, ContextId>();
|
||||
|
||||
export class AggregateByWorkspaceContextIdStrategy
|
||||
implements ContextIdStrategy
|
||||
{
|
||||
attach(contextId: ContextId, request: Request) {
|
||||
const token = request.header('Authorization')?.replace('Bearer ', '');
|
||||
const jwtPayload = token ? jwtDecode<JwtPayload>(token) : null;
|
||||
let workspaceSubTreeId: ContextId;
|
||||
|
||||
if (!jwtPayload) {
|
||||
return () => contextId;
|
||||
}
|
||||
|
||||
if (workspaces.has(jwtPayload.workspaceId)) {
|
||||
workspaceSubTreeId = workspaces.get(jwtPayload.workspaceId)!;
|
||||
} else {
|
||||
workspaceSubTreeId = ContextIdFactory.create();
|
||||
workspaces.set(jwtPayload.workspaceId, workspaceSubTreeId);
|
||||
}
|
||||
|
||||
// If tree is not durable, return the original "contextId" object
|
||||
return (info: HostComponentInfo) =>
|
||||
info.isTreeDurable ? workspaceSubTreeId : contextId;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user