Update orders modules

master
Mahdi 2 weeks ago
parent 1f90fb794b
commit ead77d5ce5
  1. 6
      src/modules/orders/orders.controller.ts
  2. 11
      src/modules/orders/orders.service.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);

@ -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(

Loading…
Cancel
Save