Skip to content

Commit 9faa420

Browse files
authored
Merge pull request #229 from import-ai/refactor/user
refactor(user): update user interceptor
2 parents 41c6443 + c0e45df commit 9faa420

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

src/interceptor/user.interceptor.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,36 @@ export class UserInterceptor implements NestInterceptor {
2323
{},
2424
context.active(),
2525
(span) => {
26+
const ctxType = executionContext.getType();
27+
let userId: string | null = null;
28+
if (ctxType === 'http') {
29+
const httpReq = executionContext.switchToHttp().getRequest();
30+
if (httpReq.user?.id) {
31+
userId = httpReq.user.id;
32+
}
33+
} else if (ctxType === 'ws') {
34+
const client = executionContext.switchToWs().getClient<Socket>();
35+
userId = client.data?.userId ?? null;
36+
}
2637
return next.handle().pipe(
2738
tap((responseBody) => {
28-
const ctxType = executionContext.getType();
29-
let userId: string | null = null;
30-
if (ctxType === 'http') {
39+
if (!userId && ctxType === 'http') {
3140
const httpReq = executionContext.switchToHttp().getRequest();
32-
if (httpReq.user?.id) {
33-
userId = httpReq.user.id;
34-
} else if (
41+
if (
3542
LOGIN_URLS.includes(httpReq.url) &&
3643
httpReq.method === 'POST' &&
3744
responseBody?.id
3845
) {
3946
userId = responseBody.id;
4047
}
41-
} else if (ctxType === 'ws') {
42-
const client = executionContext.switchToWs().getClient<Socket>();
43-
userId = client.data.userId;
4448
}
49+
}),
50+
finalize(() => {
4551
if (userId) {
4652
span.setAttribute('user.id', userId);
4753
}
54+
span.end();
4855
}),
49-
finalize(() => span.end()),
5056
);
5157
},
5258
);

src/namespaces/namespaces.service.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -273,16 +273,6 @@ export class NamespacesService {
273273
},
274274
entityManager,
275275
);
276-
await this.resourcesService.createResource(
277-
{
278-
namespaceId,
279-
parentId: privateRoot.id,
280-
userId,
281-
resourceType: ResourceType.FOLDER,
282-
name: this.i18n.t('namespace.uncategorized'),
283-
},
284-
entityManager,
285-
);
286276
return privateRoot.id;
287277
}
288278

0 commit comments

Comments
 (0)