Spaces:
Sleeping
Sleeping
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'; | |
import { paginate, Paginate, PaginateQuery } from 'nestjs-paginate'; | |
import { Roles } from '../authentication/authorization/roles.decorator.js'; | |
import { UpdateOrderDto } from './dto/update-order.dto.js'; | |
import { Request } from 'express'; | |
'branchs/:branchId/orders') | (|
export class BranchOrderController { | |
constructor(private readonly orderService: OrderService) {} | |
() | |
async create( | |
'branchId') branchId: string, ( | |
() req: Request, | |
() createOrderDto: CreateOrderDto, | |
) { | |
const ipAddr = req.headers['x-forwarded-for'] || req.socket.remoteAddress; | |
const userId = req['user'].sub; | |
const role = req['user'].role; | |
console.log(req['user']); | |
if (role === Role.CUSTOMER) { | |
console.log('customer'); | |
return this.orderService.createFromCustomer( | |
branchId, | |
userId, | |
createOrderDto, | |
ipAddr as string, | |
); | |
} else | |
return this.orderService.createFromStaff( | |
branchId, | |
userId, | |
createOrderDto, | |
); | |
} | |
'history') | (|
async findHistory( | |
() req: Request, | |
'branchId') branchId: string, ( | |
() paginateQuery: PaginateQuery, | |
) { | |
// order history of user. | |
const userId = req['user'].sub; | |
console.log(req['user']); | |
return this.orderService.findHistory(paginateQuery, userId, branchId); | |
} | |
':id') | (|
async findOne('id') id: string) { ( | |
return this.orderService.findOne(+id); | |
} | |
':id') | (|
update('id') id: string, () updateOrderDto: UpdateOrderDto) { ( | |
return this.orderService.updateOrder(+id, updateOrderDto); | |
} | |
':id') | (|
remove('id') id: string) { ( | |
return this.orderService.remove(+id); | |
} | |
} | |
Role.ADMIN, Role.STAFF, Role.BRANCH_MANAGER, Role.SHIPPER) | (|
'orders') | (|
export class OrderController { | |
constructor(private readonly orderService: OrderService) {} | |
() | |
async findAll() { () paginateQuery: PaginateQuery | |
return this.orderService.findAll(paginateQuery); | |
} | |
':id') | (|
async findOne('id') id: string) { ( | |
return this.orderService.findOne(+id); | |
} | |
':id') | (|
update('id') id: string, () updateOrderDto: UpdateOrderDto) { ( | |
return this.orderService.updateOrder(+id, updateOrderDto); | |
} | |
} | |