Skip to content

Commit

Permalink
[v1.0.5] 티켓 단건조회 수정, 주문모듈 응답값 개선
Browse files Browse the repository at this point in the history
[v1.0.5] 티켓 단건조회 수정, 주문모듈 응답값 개선
  • Loading branch information
ImNM authored Aug 9, 2022
2 parents c48c5db + 4c6cf25 commit ffccd29
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
8 changes: 6 additions & 2 deletions src/database/repositories/order.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ export class OrderRepository {
async findById(orderId: number): Promise<Order> {
const order = await this.orderRepository
.createQueryBuilder('order')
.leftJoin('order.user', 'user')
.addSelect(['user.id', 'user.name', 'user.phoneNumber', 'user.role'])
.leftJoin('order.admin', 'admin')
.addSelect(['admin.id', 'admin.name', 'admin.phoneNumber', 'admin.role'])
.where({ id: orderId })
.getOne();

Expand Down Expand Up @@ -157,7 +161,7 @@ export class OrderRepository {
.where({ status: OrderStatus.DONE })
.andWhere({ isFree: false });

let income = await queryBuilder.getRawOne();
const income = await queryBuilder.getRawOne();
if (income.sum == null) {
income.sum = 0;
}
Expand All @@ -168,7 +172,7 @@ export class OrderRepository {
const queryBuilderForFree =
this.orderRepository.createQueryBuilder('order');

let freeOrder = await queryBuilderForFree
const freeOrder = await queryBuilderForFree
.select('SUM(order.ticketCount)', 'freeTicketCount')
.where({ isFree: 'true' })
.getRawOne();
Expand Down
3 changes: 2 additions & 1 deletion src/orders/orders.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,10 @@ export class OrdersController {
@Roles(Role.Admin)
@Patch('/:orderId/free')
makeOrderFree(
@ReqUser() admin: User,
@Param('orderId', OrderIdValidationPipe) orderId: number
): Promise<Order> {
return this.orderService.makeOrderFree(orderId);
return this.orderService.makeOrderFree(orderId, admin);
}

@ApiOperation({
Expand Down
3 changes: 2 additions & 1 deletion src/orders/orders.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,11 @@ export class OrdersService {
}
}

async makeOrderFree(orderId: number): Promise<Order> {
async makeOrderFree(orderId: number, admin: User): Promise<Order> {
// orderId로 주문 찾기
const order = await this.orderRepository.findById(orderId);
order.isFree = true;
order.admin = admin;
await this.orderRepository.saveOrder(order);
return order;
}
Expand Down
9 changes: 5 additions & 4 deletions src/tickets/tickets.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,11 @@ export class TicketsController {
description: '요청 성공시',
type: Ticket
})
@ApiUnauthorizedResponse({
status: 401,
description: 'AccessToken 권한이 없을 경우'
})
// @ApiUnauthorizedResponse({
// status: 401,
// description: 'AccessToken 권한이 없을 경우'
// })
@NoAuth()
@Get('/:uuid')
getTicketByUuid(
@Param('uuid')
Expand Down
6 changes: 3 additions & 3 deletions src/tickets/tickets.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ export class TicketsService {
const ticket = await this.ticketRepository.findByUuid(ticketUuid);

//어드민이거나 Ticket.user.id === user.id 일때만 리턴
if (ticket.user.id !== user.id && user.role !== Role.Admin) {
throw new UnauthorizedException('해당 티켓에 대한 접근 권한이 없습니다');
}
// if (ticket.user.id !== user.id && user.role !== Role.Admin) {
// throw new UnauthorizedException('해당 티켓에 대한 접근 권한이 없습니다');
// }

return ticket;
}
Expand Down

0 comments on commit ffccd29

Please sign in to comment.