Trần Viết Sơn
feat: all thing about order
3367e34
raw
history blame
1.49 kB
import {
Controller,
Get,
Post,
Body,
Patch,
Param,
Delete,
Req,
} from '@nestjs/common';
import { OrderService } from './order.service.js';
import { CreateOrderDto } from './dto/create-order.dto.js';
import { Role } from '../../common/enums/role.enum.js';
@Controller('branchs/:branchId/orders')
export class OrderController {
constructor(private readonly orderService: OrderService) {}
@Post()
async create(
@Param('branchId') branchId: string,
@Req() req: Request,
@Body() createOrderDto: CreateOrderDto,
) {
const userId = req['user'].sub;
const role = req['user'].roles;
console.log(req['user']);
if (role == Role.CUSTOMER)
return this.orderService.createFromCustomer(
branchId,
userId,
createOrderDto,
);
else
return this.orderService.createFromStaff(
branchId,
userId,
createOrderDto,
);
}
@Get()
async findAll(@Req() req: Request) {
const userId = req['user'].sub;
console.log(req['user']);
return this.orderService.findAll();
}
@Get(':id')
async findOne(@Param('id') id: string) {
return this.orderService.findOne(+id);
}
// @Patch(':id')
// async update(
// @Param('id') id: string,
// @Body() updateOrderDto: UpdateOrderDto,
// ) {
// return this.orderService.update(+id, updateOrderDto);
// }
@Delete(':id')
remove(@Param('id') id: string) {
return this.orderService.remove(+id);
}
}