new endpoints
This commit is contained in:
@@ -38,7 +38,7 @@ export class OrderController {
|
||||
@UseGuards(AuthGuard)
|
||||
@ApiOperation({ summary: 'Get all orders with pagination and filters' })
|
||||
findAll(@Query() dto: FindOrdersDto, @UserId() userId: string) {
|
||||
return this.orderService.findUserOrders(userId, dto);
|
||||
return this.orderService.findOrdersAsUser(userId, dto);
|
||||
}
|
||||
|
||||
@Get('public/orders/:id')
|
||||
@@ -95,6 +95,12 @@ export class OrderController {
|
||||
return this.orderService.createOrderAsAdmin(adminId, body);
|
||||
}
|
||||
|
||||
@Get('admin/orders')
|
||||
@UseGuards(AuthGuard)
|
||||
@ApiOperation({ summary: 'Get all orders with pagination and filters' })
|
||||
findAllAsAdmin(@Query() dto: FindOrdersDto) {
|
||||
return this.orderService.findOrdersAsAdmin(dto);
|
||||
}
|
||||
|
||||
@Get('admin/orders/:id')
|
||||
@UseGuards(AdminAuthGuard)
|
||||
|
||||
@@ -39,7 +39,7 @@ export class CreateOrderItemAsUserDto {
|
||||
export class CreateOrderItemDtoAsAdmin extends CreateOrderItemAsUserDto {
|
||||
@ApiPropertyOptional({ example: [] })
|
||||
@IsArray()
|
||||
print?: IField[]
|
||||
printAttributes?: IField[]
|
||||
|
||||
@ApiPropertyOptional({ example: [] })
|
||||
@IsArray()
|
||||
@@ -101,7 +101,9 @@ export class CreateOrderAsAdminDto {
|
||||
print: [{ fieldId: '', value: '' }],
|
||||
printAttachments: [{ url: '', type: '' }],
|
||||
quantity: 100,
|
||||
attributesValues: []
|
||||
attributes: [],
|
||||
unitPrice:150000,
|
||||
discount:20000
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
@@ -60,7 +60,7 @@ export class OrderItem {
|
||||
|
||||
|
||||
@Property({ type: 'json', nullable: true })
|
||||
print?: IField[] // print form selected attributes
|
||||
printAttributes?: IField[] // print form selected attributes
|
||||
|
||||
@Property({ nullable: true, columnType: 'timestamptz' })
|
||||
confirmedAt?: Date;
|
||||
|
||||
@@ -41,7 +41,7 @@ export interface CreateOrderItem {
|
||||
unitPrice?: number
|
||||
discount?: number
|
||||
|
||||
print?: IField[]
|
||||
printAttributes?: IField[]
|
||||
printAttachments?: IAttachment[]
|
||||
designerId?: string
|
||||
}
|
||||
|
||||
@@ -196,11 +196,16 @@ export class OrderService {
|
||||
}
|
||||
|
||||
|
||||
async findUserOrders(userId: string, dto: FindOrdersDto) {
|
||||
async findOrdersAsUser(userId: string, dto: FindOrdersDto) {
|
||||
const orders = await this.orderRepository.findAllPaginated({ userId, ...dto })
|
||||
return orders
|
||||
}
|
||||
|
||||
async findOrdersAsAdmin(dto: FindOrdersDto) {
|
||||
const orders = await this.orderRepository.findAllPaginated(dto)
|
||||
return orders
|
||||
}
|
||||
|
||||
// async calculateOrder(inputOrder?: Order, orderId?: string) {
|
||||
// let order: undefined | Order = inputOrder
|
||||
|
||||
@@ -316,7 +321,7 @@ export class OrderService {
|
||||
|
||||
private async createOrderItemEntity(order: Order, dto: CreateOrderItemPopulated, em?: EntityManager) {
|
||||
const { attributes, description, quantity, attachments, discount,
|
||||
unitPrice, product, designer, print, printAttachments } = dto
|
||||
unitPrice, product, designer, printAttributes, printAttachments } = dto
|
||||
|
||||
const eM = em ?? this.em
|
||||
return eM.create(
|
||||
@@ -331,7 +336,7 @@ export class OrderService {
|
||||
discount,
|
||||
unitPrice,
|
||||
product,
|
||||
print,
|
||||
printAttributes: printAttributes,
|
||||
printAttachments
|
||||
})
|
||||
}
|
||||
@@ -441,7 +446,7 @@ export class OrderService {
|
||||
|
||||
async updateOrderItem(orderItem: OrderItem, dto: UpdateOrderItem) {
|
||||
const { attributes, description, product, quantity,
|
||||
attachments, discount, unitPrice, designer, print, printAttachments } = dto
|
||||
attachments, discount, unitPrice, designer, printAttributes, printAttachments } = dto
|
||||
|
||||
if (product && orderItem.product.id !== product.id) {
|
||||
orderItem.product = product
|
||||
@@ -475,8 +480,8 @@ export class OrderService {
|
||||
orderItem.unitPrice = unitPrice
|
||||
}
|
||||
|
||||
if (print != undefined) {
|
||||
orderItem.print = print
|
||||
if (printAttributes != undefined) {
|
||||
orderItem.printAttributes = printAttributes
|
||||
}
|
||||
|
||||
if (attributes != undefined) {
|
||||
|
||||
Reference in New Issue
Block a user