From d258d569f7b562aaeff4f7a23ae0009ea3bc2945 Mon Sep 17 00:00:00 2001 From: "saito.k" Date: Mon, 16 Oct 2023 01:34:28 +0000 Subject: [PATCH] =?UTF-8?q?Merged=20PR=20483:=20strictNullCheck=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3=E2=91=A3=EF=BC=88gateways=20,notification=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task2838: 修正④(gateways ,notification)](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/2838) - strictNullCheckの対応 - gateways配下 - feartures - notification ## レビューポイント ## UIの変更 - Before/Afterのスクショなど - スクショ置き場 ## 動作確認状況 - ローカルで確認、develop環境で確認など ## 補足 - 相談、参考資料などがあれば --- .../notification/notification.controller.ts | 17 +++++++++++++- .../templates/templates.controller.ts | 13 ++++++++--- .../workflows/workflows.controller.ts | 8 +++---- .../features/workflows/workflows.service.ts | 4 ++-- .../src/gateways/adb2c/adb2c.service.ts | 6 +++-- .../blobstorage/blobstorage.service.ts | 22 +++++++++---------- .../notificationhub.service.ts | 4 ++-- .../src/gateways/sendgrid/sendgrid.service.ts | 2 +- dictation_server/src/main.ts | 1 - 9 files changed, 50 insertions(+), 27 deletions(-) diff --git a/dictation_server/src/features/notification/notification.controller.ts b/dictation_server/src/features/notification/notification.controller.ts index c234163..0a640be 100644 --- a/dictation_server/src/features/notification/notification.controller.ts +++ b/dictation_server/src/features/notification/notification.controller.ts @@ -1,6 +1,7 @@ import { Body, Controller, + HttpException, HttpStatus, Post, Req, @@ -21,6 +22,7 @@ import { retrieveAuthorizationToken } from '../../common/http/helper'; import { AccessToken } from '../../common/token'; import jwt from 'jsonwebtoken'; import { makeContext } from '../../common/log'; +import { makeErrorResponse } from '../../common/error/makeErrorResponse'; @ApiTags('notification') @Controller('notification') @@ -57,7 +59,20 @@ export class NotificationController { const { handler, pns } = body; const accessToken = retrieveAuthorizationToken(req); - const { userId } = jwt.decode(accessToken, { json: true }) as AccessToken; + if (!accessToken) { + throw new HttpException( + makeErrorResponse('E000107'), + HttpStatus.UNAUTHORIZED, + ); + } + const decodedAccessToken = jwt.decode(accessToken, { json: true }); + if (!decodedAccessToken) { + throw new HttpException( + makeErrorResponse('E000101'), + HttpStatus.UNAUTHORIZED, + ); + } + const { userId } = decodedAccessToken as AccessToken; const context = makeContext(userId); diff --git a/dictation_server/src/features/templates/templates.controller.ts b/dictation_server/src/features/templates/templates.controller.ts index da4f061..ef972cf 100644 --- a/dictation_server/src/features/templates/templates.controller.ts +++ b/dictation_server/src/features/templates/templates.controller.ts @@ -1,4 +1,11 @@ -import { Controller, Get, HttpException, HttpStatus, Req, UseGuards } from '@nestjs/common'; +import { + Controller, + Get, + HttpException, + HttpStatus, + Req, + UseGuards, +} from '@nestjs/common'; import { ApiBearerAuth, ApiOperation, @@ -47,7 +54,7 @@ export class TemplatesController { @UseGuards(RoleGuard.requireds({ roles: [ADMIN_ROLES.ADMIN] })) @Get() async getTemplates(@Req() req: Request): Promise { - const accessToken = retrieveAuthorizationToken(req) as string; + const accessToken = retrieveAuthorizationToken(req); if (!accessToken) { throw new HttpException( makeErrorResponse('E000107'), @@ -60,7 +67,7 @@ export class TemplatesController { makeErrorResponse('E000101'), HttpStatus.UNAUTHORIZED, ); - } + } const { userId } = decodedAccessToken as AccessToken; const context = makeContext(userId); diff --git a/dictation_server/src/features/workflows/workflows.controller.ts b/dictation_server/src/features/workflows/workflows.controller.ts index 63deb5e..bf96f2a 100644 --- a/dictation_server/src/features/workflows/workflows.controller.ts +++ b/dictation_server/src/features/workflows/workflows.controller.ts @@ -67,7 +67,7 @@ export class WorkflowsController { @Get() async getWorkflows(@Req() req: Request): Promise { // TODO strictNullChecks対応 - const accessToken = retrieveAuthorizationToken(req) as string; + const accessToken = retrieveAuthorizationToken(req); if (!accessToken) { throw new HttpException( makeErrorResponse('E000107'), @@ -124,7 +124,7 @@ export class WorkflowsController { ): Promise { const { authorId, worktypeId, templateId, typists } = body; // TODO strictNullChecks対応 - const accessToken = retrieveAuthorizationToken(req) as string; + const accessToken = retrieveAuthorizationToken(req); if (!accessToken) { throw new HttpException( makeErrorResponse('E000107'), @@ -189,7 +189,7 @@ export class WorkflowsController { const { authorId, worktypeId, templateId, typists } = body; const { workflowId } = param; // TODO strictNullChecks対応 - const accessToken = retrieveAuthorizationToken(req) as string; + const accessToken = retrieveAuthorizationToken(req); if (!accessToken) { throw new HttpException( makeErrorResponse('E000107'), @@ -253,7 +253,7 @@ export class WorkflowsController { ): Promise { const { workflowId } = param; // TODO strictNullChecks対応 - const accessToken = retrieveAuthorizationToken(req) as string; + const accessToken = retrieveAuthorizationToken(req); if (!accessToken) { throw new HttpException( makeErrorResponse('E000107'), diff --git a/dictation_server/src/features/workflows/workflows.service.ts b/dictation_server/src/features/workflows/workflows.service.ts index 4dbc95c..b8be4e6 100644 --- a/dictation_server/src/features/workflows/workflows.service.ts +++ b/dictation_server/src/features/workflows/workflows.service.ts @@ -58,7 +58,7 @@ export class WorkflowsService { }); // externalIdsからundefinedを除外 const filteredExternalIds = externalIds.filter( - (externalId):externalId is string => externalId !== undefined, + (externalId): externalId is string => externalId !== undefined, ); // externalIdsから重複を除外 const distinctedExternalIds = [...new Set(filteredExternalIds)]; @@ -98,7 +98,7 @@ export class WorkflowsService { (adb2cUser) => adb2cUser.id === typist.external_id, )?.displayName : typistGroup?.name; - + if (!typistName) { throw new Error('typistName is undefined'); } diff --git a/dictation_server/src/gateways/adb2c/adb2c.service.ts b/dictation_server/src/gateways/adb2c/adb2c.service.ts index 6a41b2b..9f22a17 100644 --- a/dictation_server/src/gateways/adb2c/adb2c.service.ts +++ b/dictation_server/src/gateways/adb2c/adb2c.service.ts @@ -30,8 +30,10 @@ export const isConflictError = (arg: unknown): arg is ConflictError => { @Injectable() export class AdB2cService { private readonly logger = new Logger(AdB2cService.name); - private readonly tenantName = this.configService.getOrThrow('TENANT_NAME'); - private readonly flowName = this.configService.getOrThrow('SIGNIN_FLOW_NAME'); + private readonly tenantName = + this.configService.getOrThrow('TENANT_NAME'); + private readonly flowName = + this.configService.getOrThrow('SIGNIN_FLOW_NAME'); private graphClient: Client; constructor(private readonly configService: ConfigService) { diff --git a/dictation_server/src/gateways/blobstorage/blobstorage.service.ts b/dictation_server/src/gateways/blobstorage/blobstorage.service.ts index 57dd908..8d8b91e 100644 --- a/dictation_server/src/gateways/blobstorage/blobstorage.service.ts +++ b/dictation_server/src/gateways/blobstorage/blobstorage.service.ts @@ -28,31 +28,31 @@ export class BlobstorageService { private readonly sasTokenExpireHour: number; constructor(private readonly configService: ConfigService) { this.sharedKeyCredentialUS = new StorageSharedKeyCredential( - this.configService.get('STORAGE_ACCOUNT_NAME_US'), - this.configService.get('STORAGE_ACCOUNT_KEY_US'), + this.configService.getOrThrow('STORAGE_ACCOUNT_NAME_US'), + this.configService.getOrThrow('STORAGE_ACCOUNT_KEY_US'), ); this.sharedKeyCredentialAU = new StorageSharedKeyCredential( - this.configService.get('STORAGE_ACCOUNT_NAME_AU'), - this.configService.get('STORAGE_ACCOUNT_KEY_AU'), + this.configService.getOrThrow('STORAGE_ACCOUNT_NAME_AU'), + this.configService.getOrThrow('STORAGE_ACCOUNT_KEY_AU'), ); this.sharedKeyCredentialEU = new StorageSharedKeyCredential( - this.configService.get('STORAGE_ACCOUNT_NAME_EU'), - this.configService.get('STORAGE_ACCOUNT_KEY_EU'), + this.configService.getOrThrow('STORAGE_ACCOUNT_NAME_EU'), + this.configService.getOrThrow('STORAGE_ACCOUNT_KEY_EU'), ); this.blobServiceClientUS = new BlobServiceClient( - this.configService.get('STORAGE_ACCOUNT_ENDPOINT_US'), + this.configService.getOrThrow('STORAGE_ACCOUNT_ENDPOINT_US'), this.sharedKeyCredentialUS, ); this.blobServiceClientAU = new BlobServiceClient( - this.configService.get('STORAGE_ACCOUNT_ENDPOINT_AU'), + this.configService.getOrThrow('STORAGE_ACCOUNT_ENDPOINT_AU'), this.sharedKeyCredentialAU, ); this.blobServiceClientEU = new BlobServiceClient( - this.configService.get('STORAGE_ACCOUNT_ENDPOINT_EU'), + this.configService.getOrThrow('STORAGE_ACCOUNT_ENDPOINT_EU'), this.sharedKeyCredentialEU, ); - this.sasTokenExpireHour = Number( - this.configService.get('STORAGE_TOKEN_EXPIRE_TIME'), + this.sasTokenExpireHour = this.configService.getOrThrow( + 'STORAGE_TOKEN_EXPIRE_TIME', ); } diff --git a/dictation_server/src/gateways/notificationhub/notificationhub.service.ts b/dictation_server/src/gateways/notificationhub/notificationhub.service.ts index 679eef2..22038cc 100644 --- a/dictation_server/src/gateways/notificationhub/notificationhub.service.ts +++ b/dictation_server/src/gateways/notificationhub/notificationhub.service.ts @@ -18,8 +18,8 @@ export class NotificationhubService { private readonly client: NotificationHubsClient; constructor(private readonly configService: ConfigService) { this.client = new NotificationHubsClient( - this.configService.get('NOTIFICATION_HUB_CONNECT_STRING')??"", - this.configService.get('NOTIFICATION_HUB_NAME')??"", + this.configService.getOrThrow('NOTIFICATION_HUB_CONNECT_STRING'), + this.configService.getOrThrow('NOTIFICATION_HUB_NAME'), ); } diff --git a/dictation_server/src/gateways/sendgrid/sendgrid.service.ts b/dictation_server/src/gateways/sendgrid/sendgrid.service.ts index 3fb3e66..1b29705 100644 --- a/dictation_server/src/gateways/sendgrid/sendgrid.service.ts +++ b/dictation_server/src/gateways/sendgrid/sendgrid.service.ts @@ -9,7 +9,7 @@ import { Context } from '../../common/log'; export class SendGridService { private readonly logger = new Logger(SendGridService.name); constructor(private readonly configService: ConfigService) { - const key = this.configService.get('SENDGRID_API_KEY'); + const key = this.configService.getOrThrow('SENDGRID_API_KEY'); sendgrid.setApiKey(key); } diff --git a/dictation_server/src/main.ts b/dictation_server/src/main.ts index 7943c9a..eec7370 100644 --- a/dictation_server/src/main.ts +++ b/dictation_server/src/main.ts @@ -16,7 +16,6 @@ helmetDirectives['connect-src'] = process.env.STORAGE_ACCOUNT_ENDPOINT_EU ?? '', ] : ["'self'"]; - helmetDirectives['navigate-to'] = ["'self'"]; helmetDirectives['style-src'] = ["'self'", 'https:'];