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