create invoice

This commit is contained in:
2026-01-17 23:49:48 +03:30
parent d6d371b13a
commit 90de3c743d
2 changed files with 7 additions and 12 deletions
+4 -5
View File
@@ -7,9 +7,9 @@ import { ApiProperty } from '@nestjs/swagger';
import { Type } from 'class-transformer';
export class InvoiceItemDto {
@IsInt()
@IsNumber()
@ApiProperty()
orderItemId: bigint;
orderItemId: number;
@ApiProperty()
@IsNumber()
@@ -22,9 +22,8 @@ export class CreateInvoiceDto {
@ApiProperty({
isArray: true, type: [InvoiceItemDto], example: [
{
productId: 1,
quantity: 100,
attributesValues: []
orderItemId: 1,
unitPrice: 100,
}
]
})
@@ -28,7 +28,6 @@ import { CreateInvoiceDto } from '../dto/create-invoice.dto';
export class OrdersService {
private readonly logger = new Logger(OrdersService.name);
constructor(
private readonly em: EntityManager,
private readonly orderRepository: OrderRepository,
@@ -123,10 +122,6 @@ export class OrdersService {
const targetOrder = await this.findOneOrFail(orderId)
// set price for order items
// calculate order financials
// change status
if (items.length !== targetOrder.items.length) {
throw new BadRequestException("One or more order items price is not set")
}
@@ -136,9 +131,10 @@ export class OrdersService {
let subTotal = 0
// 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) {
throw new BadRequestException(`order item ${orderItem} not found`)
}