create invoice
This commit is contained in:
@@ -7,9 +7,9 @@ import { ApiProperty } from '@nestjs/swagger';
|
|||||||
import { Type } from 'class-transformer';
|
import { Type } from 'class-transformer';
|
||||||
|
|
||||||
export class InvoiceItemDto {
|
export class InvoiceItemDto {
|
||||||
@IsInt()
|
@IsNumber()
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
orderItemId: bigint;
|
orderItemId: number;
|
||||||
|
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
@@ -22,9 +22,8 @@ export class CreateInvoiceDto {
|
|||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
isArray: true, type: [InvoiceItemDto], example: [
|
isArray: true, type: [InvoiceItemDto], example: [
|
||||||
{
|
{
|
||||||
productId: 1,
|
orderItemId: 1,
|
||||||
quantity: 100,
|
unitPrice: 100,
|
||||||
attributesValues: []
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import { CreateInvoiceDto } from '../dto/create-invoice.dto';
|
|||||||
export class OrdersService {
|
export class OrdersService {
|
||||||
private readonly logger = new Logger(OrdersService.name);
|
private readonly logger = new Logger(OrdersService.name);
|
||||||
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly em: EntityManager,
|
private readonly em: EntityManager,
|
||||||
private readonly orderRepository: OrderRepository,
|
private readonly orderRepository: OrderRepository,
|
||||||
@@ -123,10 +122,6 @@ export class OrdersService {
|
|||||||
|
|
||||||
const targetOrder = await this.findOneOrFail(orderId)
|
const targetOrder = await this.findOneOrFail(orderId)
|
||||||
|
|
||||||
// set price for order items
|
|
||||||
// calculate order financials
|
|
||||||
// change status
|
|
||||||
|
|
||||||
if (items.length !== targetOrder.items.length) {
|
if (items.length !== targetOrder.items.length) {
|
||||||
throw new BadRequestException("One or more order items price is not set")
|
throw new BadRequestException("One or more order items price is not set")
|
||||||
}
|
}
|
||||||
@@ -136,9 +131,10 @@ export class OrdersService {
|
|||||||
|
|
||||||
let subTotal = 0
|
let subTotal = 0
|
||||||
// Calculate order item finnicials
|
// Calculate order item finnicials
|
||||||
for (const orderItem of targetOrder.items) {
|
|
||||||
|
|
||||||
const found = items.find(it => it.orderItemId === orderItem.id)
|
for (let orderItem of targetOrder.items) {
|
||||||
|
|
||||||
|
const found = items.find(it => it.orderItemId == Number(orderItem.id))
|
||||||
if (!found) {
|
if (!found) {
|
||||||
throw new BadRequestException(`order item ${orderItem} not found`)
|
throw new BadRequestException(`order item ${orderItem} not found`)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user