Merged PR 124: [PBI1221指摘対応]ライセンス注文APIの中で画面から渡ってきたパラメータのバリデーションを行う
## 概要 [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以外もセルフチェックを行いました。
This commit is contained in:
parent
0ca766f309
commit
890b004a9c
@ -8,6 +8,7 @@ import {
|
|||||||
} from './test/liscense.service.mock';
|
} from './test/liscense.service.mock';
|
||||||
import { makeErrorResponse } from '../../common/error/makeErrorResponse';
|
import { makeErrorResponse } from '../../common/error/makeErrorResponse';
|
||||||
import { HttpException, HttpStatus } from '@nestjs/common';
|
import { HttpException, HttpStatus } from '@nestjs/common';
|
||||||
|
import { PoNumberAlreadyExistError } from '../../repositories/licenses/licenses.repository.service';
|
||||||
|
|
||||||
describe('LicensesService', () => {
|
describe('LicensesService', () => {
|
||||||
it('ライセンス注文が完了する', async () => {
|
it('ライセンス注文が完了する', async () => {
|
||||||
@ -86,9 +87,7 @@ describe('LicensesService', () => {
|
|||||||
it('POナンバー重複時、エラーとなる', async () => {
|
it('POナンバー重複時、エラーとなる', async () => {
|
||||||
const lisencesRepositoryMockValue =
|
const lisencesRepositoryMockValue =
|
||||||
makeDefaultLicensesRepositoryMockValue();
|
makeDefaultLicensesRepositoryMockValue();
|
||||||
lisencesRepositoryMockValue.order = new Error(
|
lisencesRepositoryMockValue.order = new PoNumberAlreadyExistError();
|
||||||
'Email already verified user Error.',
|
|
||||||
);
|
|
||||||
const usersRepositoryMockValue = makeDefaultUsersRepositoryMockValue();
|
const usersRepositoryMockValue = makeDefaultUsersRepositoryMockValue();
|
||||||
const accountsRepositoryMockValue =
|
const accountsRepositoryMockValue =
|
||||||
makeDefaultAccountsRepositoryMockValue();
|
makeDefaultAccountsRepositoryMockValue();
|
||||||
@ -105,7 +104,7 @@ describe('LicensesService', () => {
|
|||||||
service.licenseOrders(token, body.poNumber, body.orderCount),
|
service.licenseOrders(token, body.poNumber, body.orderCount),
|
||||||
).rejects.toEqual(
|
).rejects.toEqual(
|
||||||
new HttpException(
|
new HttpException(
|
||||||
makeErrorResponse('E009999'),
|
makeErrorResponse('E010401'),
|
||||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1,9 +1,6 @@
|
|||||||
import { HttpException, HttpStatus, Injectable, Logger } from '@nestjs/common';
|
import { HttpException, HttpStatus, Injectable, Logger } from '@nestjs/common';
|
||||||
import { request } from 'http';
|
|
||||||
import { makeErrorResponse } from '../../common/error/makeErrorResponse';
|
import { makeErrorResponse } from '../../common/error/makeErrorResponse';
|
||||||
import { CryptoService } from '../../gateways/crypto/crypto.service';
|
|
||||||
import { AccessToken } from 'src/common/token';
|
import { AccessToken } from 'src/common/token';
|
||||||
import { User as EntityUser } from '../../repositories/users/entity/user.entity';
|
|
||||||
import {
|
import {
|
||||||
UsersRepositoryService,
|
UsersRepositoryService,
|
||||||
UserNotFoundError,
|
UserNotFoundError,
|
||||||
@ -16,8 +13,6 @@ import {
|
|||||||
LicensesRepositoryService,
|
LicensesRepositoryService,
|
||||||
PoNumberAlreadyExistError,
|
PoNumberAlreadyExistError,
|
||||||
} from '../../repositories/licenses/licenses.repository.service';
|
} from '../../repositories/licenses/licenses.repository.service';
|
||||||
import { CreateOrdersRequest } from './types/types';
|
|
||||||
import { DataSource } from 'typeorm';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class LicensesService {
|
export class LicensesService {
|
||||||
|
|||||||
@ -1,10 +1,15 @@
|
|||||||
import { ApiProperty } from '@nestjs/swagger';
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
import { IsInt, Matches, Max, Min } from 'class-validator';
|
||||||
|
|
||||||
export class CreateOrdersRequest {
|
export class CreateOrdersRequest {
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
|
@Matches(/^[A-Z0-9]+$/)
|
||||||
poNumber: string;
|
poNumber: string;
|
||||||
|
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
|
@IsInt()
|
||||||
|
@Min(1)
|
||||||
|
@Max(9999)
|
||||||
orderCount: number;
|
orderCount: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user