From 85a79127b0b1a470cbdefc0809eb77a71b601f35 Mon Sep 17 00:00:00 2001 From: fantasticit Date: Mon, 11 Apr 2022 22:01:51 +0800 Subject: [PATCH] fix: fix js error --- packages/server/src/guard/document-auth.guard.ts | 3 ++- packages/server/src/guard/document-status.guard.ts | 2 +- packages/server/src/guard/wiki-status.guard.ts | 2 +- packages/server/src/guard/wiki-user.guard.ts | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/server/src/guard/document-auth.guard.ts b/packages/server/src/guard/document-auth.guard.ts index 0e2c414..f701e9e 100644 --- a/packages/server/src/guard/document-auth.guard.ts +++ b/packages/server/src/guard/document-auth.guard.ts @@ -32,7 +32,8 @@ export class DocumentAuthorityGuard implements CanActivate { const user = this.jwtService.decode(token) as IUser; const { params, query, body } = request; - const documentId = params.id || params.documentId || query.id || query.documentId || body.documentId; + const documentId = params?.id || params?.documentId || query?.id || query?.documentId || body?.documentId; + let document = null; if (documentId) { diff --git a/packages/server/src/guard/document-status.guard.ts b/packages/server/src/guard/document-status.guard.ts index 2efcc14..e16db92 100644 --- a/packages/server/src/guard/document-status.guard.ts +++ b/packages/server/src/guard/document-status.guard.ts @@ -19,7 +19,7 @@ export class DocumentStatusGuard implements CanActivate { const request = context.switchToHttp().getRequest(); const { params, query, body } = request; - const documentId = params.id || params.documentId || query.id || query.documentId || body.documentId; + const documentId = params?.id || params?.documentId || query?.id || query?.documentId || body?.documentId; let document = null; diff --git a/packages/server/src/guard/wiki-status.guard.ts b/packages/server/src/guard/wiki-status.guard.ts index 69ae668..bfcd91a 100644 --- a/packages/server/src/guard/wiki-status.guard.ts +++ b/packages/server/src/guard/wiki-status.guard.ts @@ -19,7 +19,7 @@ export class WikiStatusGuard implements CanActivate { const request = context.switchToHttp().getRequest(); const { params, query, body } = request; - const wikiId = params.id || params.wikiId || query.id || query.wikiId || body.wikiId; + const wikiId = params?.id || params?.wikiId || query?.id || query?.wikiId || body?.wikiId; const wiki = await this.wikiService.findById(wikiId); diff --git a/packages/server/src/guard/wiki-user.guard.ts b/packages/server/src/guard/wiki-user.guard.ts index 9256d8e..8089c77 100644 --- a/packages/server/src/guard/wiki-user.guard.ts +++ b/packages/server/src/guard/wiki-user.guard.ts @@ -35,7 +35,7 @@ export class WikiUserRoleGuard implements CanActivate { const user = this.jwtService.decode(token) as IUser; const { params, query, body } = request; - const wikiId = params.id || params.wikiId || query.id || query.wikiId || body.wikiId; + const wikiId = params?.id || params?.wikiId || query?.id || query?.wikiId || body?.wikiId; const wiki = await this.wikiService.findById(wikiId);