Skip to content

Commit

Permalink
refactor: http 응답값 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
SeungGwan123 committed Nov 19, 2024
1 parent 3fde2da commit 4732ce4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions packages/server/src/trade/trade-ask.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,23 @@ export class AskService implements OnModuleInit {
if (!userAccount) {
throw new UnprocessableEntityException({
message: '유저가 존재하지 않습니다.',
code: 422,
statusCode: 422,
});
}

await this.tradeRepository.createTrade(askDto, user.userId,'sell', queryRunner);
await queryRunner.commitTransaction();

return {
code: 200,
statusCode: 200,
message: '거래가 정상적으로 등록되었습니다.',
};
} catch (error) {
console.log(error);
await queryRunner.rollbackTransaction();
if (error instanceof UnprocessableEntityException) throw error;
return new UnprocessableEntityException({
code: 422,
statusCode: 422,
message: '거래 등록에 실패했습니다.',
});
} finally {
Expand Down Expand Up @@ -141,7 +141,7 @@ export class AskService implements OnModuleInit {
}

return {
code: 200,
statusCode: 200,
message: '거래가 정상적으로 등록되었습니다.',
};
} catch (error) {
Expand Down
10 changes: 5 additions & 5 deletions packages/server/src/trade/trade-bid.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class BidService implements OnModuleInit {
if (!userAccount) {
throw new UnprocessableEntityException({
message: '유저가 존재하지 않습니다.',
code: 422,
statusCode: 422,
});
}
const accountBalance = await this.checkCurrency(user, bidDto);
Expand All @@ -63,15 +63,15 @@ export class BidService implements OnModuleInit {
await this.tradeRepository.createTrade(bidDto, user.userId, 'buy', queryRunner);
await queryRunner.commitTransaction();
return {
code: 200,
statusCode: 200,
message: '거래가 정상적으로 등록되었습니다.',
};
} catch (error) {
console.log(error);
await queryRunner.rollbackTransaction();
if (error instanceof UnprocessableEntityException) throw error;
return new UnprocessableEntityException({
code: 422,
statusCode: 422,
message: '거래 등록에 실패했습니다.',
});
} finally {
Expand All @@ -93,7 +93,7 @@ export class BidService implements OnModuleInit {
if (accountResult < 0){
throw new UnprocessableEntityException({
message: '자산이 부족합니다.',
code: 422,
statusCode: 422,
});
}
return accountResult;
Expand Down Expand Up @@ -128,7 +128,7 @@ export class BidService implements OnModuleInit {
}

return {
code: 200,
statusCode: 200,
message: '거래가 정상적으로 등록되었습니다.',
};
} catch (error) {
Expand Down
6 changes: 3 additions & 3 deletions packages/server/src/trade/trade.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class TradeService {
})
if(!account) {
return {
code :400,
statusCode :400,
message: "등록되지 않은 사용자입니다."
}
}
Expand All @@ -37,12 +37,12 @@ export class TradeService {
})
if(coinData){
return {
code : 200,
statusCode : 200,
message: "보유하고 계신 코인입니다."
}
}else{
return {
code : 422,
statusCode : 422,
message : "보유하지 않은 코인입니다."
}
}
Expand Down

0 comments on commit 4732ce4

Please sign in to comment.