From 890b004a9cf0be305551acc55093a6f6d84af2a9 Mon Sep 17 00:00:00 2001 From: "maruyama.t" Date: Mon, 5 Jun 2023 07:06:20 +0000 Subject: [PATCH] =?UTF-8?q?Merged=20PR=20124:=20[PBI1221=E6=8C=87=E6=91=98?= =?UTF-8?q?=E5=AF=BE=E5=BF=9C]=E3=83=A9=E3=82=A4=E3=82=BB=E3=83=B3?= =?UTF-8?q?=E3=82=B9=E6=B3=A8=E6=96=87API=E3=81=AE=E4=B8=AD=E3=81=A7?= =?UTF-8?q?=E7=94=BB=E9=9D=A2=E3=81=8B=E3=82=89=E6=B8=A1=E3=81=A3=E3=81=A6?= =?UTF-8?q?=E3=81=8D=E3=81=9F=E3=83=91=E3=83=A9=E3=83=A1=E3=83=BC=E3=82=BF?= =?UTF-8?q?=E3=81=AE=E3=83=90=E3=83=AA=E3=83=87=E3=83=BC=E3=82=B7=E3=83=A7?= =?UTF-8?q?=E3=83=B3=E3=82=92=E8=A1=8C=E3=81=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task1901: [PBI1221指摘対応]ライセンス注文APIの中で画面から渡ってきたパラメータのバリデーションを行う](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/1901) - バリデーションチェック処理をコントローラに追加 - 未使用のimportを削除 - エラーテストで比較するメッセージが間違っていたので合わせて修正 ## レビューポイント - バリデーションのタイミングは適切か - バリデーションの範囲に過不足がないか ## UIの変更 - なし ## 動作確認状況 - ローカルで確認 ## 補足 - licenses.controller.ts以外もセルフチェックを行いました。 --- .../src/features/licenses/licenses.service.spec.ts | 7 +++---- dictation_server/src/features/licenses/licenses.service.ts | 5 ----- dictation_server/src/features/licenses/types/types.ts | 5 +++++ 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/dictation_server/src/features/licenses/licenses.service.spec.ts b/dictation_server/src/features/licenses/licenses.service.spec.ts index df0cc52..3d700a0 100644 --- a/dictation_server/src/features/licenses/licenses.service.spec.ts +++ b/dictation_server/src/features/licenses/licenses.service.spec.ts @@ -8,6 +8,7 @@ import { } from './test/liscense.service.mock'; import { makeErrorResponse } from '../../common/error/makeErrorResponse'; import { HttpException, HttpStatus } from '@nestjs/common'; +import { PoNumberAlreadyExistError } from '../../repositories/licenses/licenses.repository.service'; describe('LicensesService', () => { it('ライセンス注文が完了する', async () => { @@ -86,9 +87,7 @@ describe('LicensesService', () => { it('POナンバー重複時、エラーとなる', async () => { const lisencesRepositoryMockValue = makeDefaultLicensesRepositoryMockValue(); - lisencesRepositoryMockValue.order = new Error( - 'Email already verified user Error.', - ); + lisencesRepositoryMockValue.order = new PoNumberAlreadyExistError(); const usersRepositoryMockValue = makeDefaultUsersRepositoryMockValue(); const accountsRepositoryMockValue = makeDefaultAccountsRepositoryMockValue(); @@ -105,7 +104,7 @@ describe('LicensesService', () => { service.licenseOrders(token, body.poNumber, body.orderCount), ).rejects.toEqual( new HttpException( - makeErrorResponse('E009999'), + makeErrorResponse('E010401'), HttpStatus.INTERNAL_SERVER_ERROR, ), ); diff --git a/dictation_server/src/features/licenses/licenses.service.ts b/dictation_server/src/features/licenses/licenses.service.ts index 94d24b2..af402c7 100644 --- a/dictation_server/src/features/licenses/licenses.service.ts +++ b/dictation_server/src/features/licenses/licenses.service.ts @@ -1,9 +1,6 @@ import { HttpException, HttpStatus, Injectable, Logger } from '@nestjs/common'; -import { request } from 'http'; import { makeErrorResponse } from '../../common/error/makeErrorResponse'; -import { CryptoService } from '../../gateways/crypto/crypto.service'; import { AccessToken } from 'src/common/token'; -import { User as EntityUser } from '../../repositories/users/entity/user.entity'; import { UsersRepositoryService, UserNotFoundError, @@ -16,8 +13,6 @@ import { LicensesRepositoryService, PoNumberAlreadyExistError, } from '../../repositories/licenses/licenses.repository.service'; -import { CreateOrdersRequest } from './types/types'; -import { DataSource } from 'typeorm'; @Injectable() export class LicensesService { diff --git a/dictation_server/src/features/licenses/types/types.ts b/dictation_server/src/features/licenses/types/types.ts index c34f0d1..8fe94aa 100644 --- a/dictation_server/src/features/licenses/types/types.ts +++ b/dictation_server/src/features/licenses/types/types.ts @@ -1,10 +1,15 @@ import { ApiProperty } from '@nestjs/swagger'; +import { IsInt, Matches, Max, Min } from 'class-validator'; export class CreateOrdersRequest { @ApiProperty() + @Matches(/^[A-Z0-9]+$/) poNumber: string; @ApiProperty() + @IsInt() + @Min(1) + @Max(9999) orderCount: number; }