diff --git a/src/modules/orders/orders.controller.ts b/src/modules/orders/orders.controller.ts index d19d4a2..3edf4fd 100644 --- a/src/modules/orders/orders.controller.ts +++ b/src/modules/orders/orders.controller.ts @@ -10,6 +10,7 @@ import { import { OrdersService } from './orders.service'; import { CreateOrderDto } from './dto/create-order.dto'; import { UpdateOrderDto } from './dto/update-order.dto'; +import { UUID } from 'crypto'; @Controller('orders') export class OrdersController { @@ -25,6 +26,11 @@ export class OrdersController { return this.ordersService.findAll(); } + @Get('users/:id') + findByUser(@Param('id') id: UUID) { + return this.ordersService.findByUser(id); + } + @Get(':id') findOne(@Param('id') id: string) { return this.ordersService.findOne(+id); diff --git a/src/modules/orders/orders.service.ts b/src/modules/orders/orders.service.ts index a5e84fd..09bce82 100644 --- a/src/modules/orders/orders.service.ts +++ b/src/modules/orders/orders.service.ts @@ -4,6 +4,7 @@ import { Order } from './entities/order.entity'; import { ORDER_REPOSITORY } from 'src/core/constants'; import { OrderStatuses } from './entities/order-status.entity'; import { User } from '../users/entities/user.entity'; +import { UUID } from 'crypto'; @Injectable() export class OrdersService { @@ -30,6 +31,16 @@ export class OrdersService { }); } + async findByUser(id: UUID) { + return await this.orderRepository.findAll({ + include: { + model: User, + where: { uuid: id }, + attributes: ['firstName', 'lastName'], + }, + }); + } + async update(id: number, updateOrderDto: UpdateOrderDto) { const [numberOfAffectedRows, [updatedOrder]] = await this.orderRepository.update(