order kitem entity update
This commit is contained in:
@@ -35,8 +35,8 @@ export class OrderService {
|
||||
private readonly adminRepository: AdminRepository,
|
||||
) { }
|
||||
|
||||
async createOrder(userId: string, dto: CreateOrderDto) {
|
||||
const { attachments, content, items } = dto
|
||||
async createNewOrder(userId: string, dto: CreateOrderDto) {
|
||||
const { items } = dto
|
||||
|
||||
const order = await this.em.transactional(async (em) => {
|
||||
const user = await this.userService.findById(userId)
|
||||
@@ -48,7 +48,6 @@ export class OrderService {
|
||||
user,
|
||||
discount: 0,
|
||||
subTotal: 0,
|
||||
orderNumber: 1,
|
||||
total: 0,
|
||||
paidAmount: 0,
|
||||
balance: 0,
|
||||
@@ -79,19 +78,13 @@ export class OrderService {
|
||||
unitPrice: 0,
|
||||
total: 0,
|
||||
subTotal: 0,
|
||||
discount: 0
|
||||
discount: 0,
|
||||
attachments: item.attachments,
|
||||
description: item.description
|
||||
})
|
||||
em.persist(orderItem)
|
||||
});
|
||||
|
||||
const ticket = this.ticketRepository.create({
|
||||
content,
|
||||
user,
|
||||
attachments,
|
||||
admin: null,
|
||||
order
|
||||
})
|
||||
em.persist(ticket)
|
||||
|
||||
await em.flush()
|
||||
|
||||
@@ -102,7 +95,7 @@ export class OrderService {
|
||||
}
|
||||
|
||||
async createOrdeAsAdmin(adminId: string, dto: CreateOrderAsAdminDto) {
|
||||
const { attachments, content, items, discount, userPhone } = dto
|
||||
const { items, userPhone } = dto
|
||||
|
||||
const user = await this.userService.findByPhone(userPhone)
|
||||
if (!user) {
|
||||
@@ -116,18 +109,14 @@ export class OrderService {
|
||||
|
||||
const order = await this.em.transactional(async (em) => {
|
||||
|
||||
let subTotal = 0
|
||||
items.forEach(item => { subTotal += item.unitPrice * item.quantity })
|
||||
const total = subTotal - discount
|
||||
|
||||
const order = this.orderRepository.create({
|
||||
creator: admin,
|
||||
user,
|
||||
discount,
|
||||
subTotal,
|
||||
total,
|
||||
discount: 0,
|
||||
subTotal: 0,
|
||||
total: 0,
|
||||
paidAmount: 0,
|
||||
balance: total,
|
||||
balance: 0,
|
||||
status: OrderStatusEnum.INVOICED,
|
||||
taxAmount: 0
|
||||
})
|
||||
@@ -150,7 +139,6 @@ export class OrderService {
|
||||
throw new BadRequestException(`product ${product} not found`)
|
||||
}
|
||||
|
||||
|
||||
const orderItem = this.orderItemRepository.create({
|
||||
order,
|
||||
attributesValues: item.attributesValues,
|
||||
@@ -165,16 +153,7 @@ export class OrderService {
|
||||
em.persist(orderItem)
|
||||
});
|
||||
|
||||
|
||||
const ticket = this.ticketRepository.create({
|
||||
content,
|
||||
user,
|
||||
attachments,
|
||||
admin: null,
|
||||
order
|
||||
})
|
||||
|
||||
em.persist(ticket)
|
||||
// TODO : calculation must be done after create order
|
||||
|
||||
await em.flush()
|
||||
|
||||
@@ -185,7 +164,7 @@ export class OrderService {
|
||||
|
||||
}
|
||||
|
||||
async findAllForUser(userId: string, dto: FindOrdersDto) {
|
||||
async findUserOrders(userId: string, dto: FindOrdersDto) {
|
||||
const orders = await this.orderRepository.findAllPaginated({ userId, ...dto })
|
||||
return orders
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user