Skip to content

Commit

Permalink
Merge pull request #83 from jihwooon/issue-54
Browse files Browse the repository at this point in the history
form-data 요청 시 string 타입을 number타입으로 형변환을 하라
  • Loading branch information
jihwooon authored Oct 23, 2023
2 parents be42478 + e3345cc commit fabc792
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
22 changes: 12 additions & 10 deletions server/src/items/application/item.creater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,23 @@ export class ItemCreater {
) {}

async registerItem(items: Item, email: string, files: Express.Multer.File[]): Promise<number> {
const { itemName, itemDetail, price, stockNumber, itemSellStatus } = items

const member = await this.memberRepository.findByEmail(email)
if (!member) {
throw new MemberNotFoundException('회원 정보를 찾을 수 없습니다')
}

const savedItem = new Item({
itemName: items.itemName,
itemDetail: items.itemDetail,
price: items.price,
stockNumber: items.stockNumber,
sellStatus: items.itemSellStatus,
member: member,
})

const savedId = await this.itemRepository.save(savedItem)
const savedId = await this.itemRepository.save(
new Item({
itemName: itemName,
itemDetail: itemDetail,
price: price,
stockNumber: stockNumber,
sellStatus: itemSellStatus,
member: member,
}),
)
await this.itemImageService.saveItemImages(savedId, files)

if (!savedId) {
Expand Down
2 changes: 0 additions & 2 deletions server/src/items/dto/save-item.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ export class CreateItemRequest {
itemDetail: string

@IsNotEmpty({ message: '가격은 필수 입력 값입니다.' })
@IsNumber()
price: number

@IsNotEmpty({ message: '재고는 필수 입력 값입니다.' })
@IsNumber()
stockNumber: number

@IsEnum({ sellStatus: ItemStatusEnum.SELL })
Expand Down
4 changes: 2 additions & 2 deletions server/src/items/web/item-create.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export class ItemCreateController {
new Item({
itemName: itemName,
itemDetail: itemDetail,
price: price,
stockNumber: stockNumber,
price: Number(price),
stockNumber: Number(stockNumber),
sellStatus: sellStatus,
}),
email,
Expand Down
7 changes: 2 additions & 5 deletions server/test/item-create.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ describe('ItemCreateController (e2e)', () => {
expect(status).toEqual(400)
expect(body).toEqual({
error: 'Bad Request',
message: ['price must be a number conforming to the specified constraints', '가격은 필수 입력 값입니다.'],
message: ['가격은 필수 입력 값입니다.'],
statusCode: 400,
})
})
Expand All @@ -337,10 +337,7 @@ describe('ItemCreateController (e2e)', () => {
expect(status).toEqual(400)
expect(body).toEqual({
error: 'Bad Request',
message: [
'stockNumber must be a number conforming to the specified constraints',
'재고는 필수 입력 값입니다.',
],
message: ['재고는 필수 입력 값입니다.'],
statusCode: 400,
})
})
Expand Down

0 comments on commit fabc792

Please sign in to comment.