This commit is contained in:
2026-02-21 16:44:49 +03:30
parent 408290bf5a
commit 9bc025f1ae
2 changed files with 53 additions and 54 deletions
+43 -43
View File
@@ -48,27 +48,26 @@ export class OrderService {
let invoiceItem: null | InvoiceItem = null
let user: User | null = null
if (dto.invoiceItemId) {
invoiceItem = await this.em.findOne(InvoiceItem, { id: dto.invoiceItemId }, { populate: ['invoice', 'invoice.user'] });
if (!invoiceItem) {
throw new NotFoundException(`Invoice item with ID ${dto.invoiceItemId} not found.`);
}
user = invoiceItem.invoice.user
}
invoiceItem = await this.em.findOne(InvoiceItem, { id: dto.invoiceItemId }, { populate: ['invoice', 'invoice.user','product'] });
if (!invoiceItem) {
if (!dto.userId) {
throw new NotFoundException(`UserId is mandatory`);
}
const user = await this.userService.findById(dto.userId);
if (!user) {
throw new NotFoundException(`User with ID ${dto.userId} not found.`);
}
throw new NotFoundException(`Invoice item with ID ${dto.invoiceItemId} not found.`);
}
user = invoiceItem.invoice.user
// if (!invoiceItem) {
// if (!dto.userId) {
// throw new NotFoundException(`UserId is mandatory`);
// }
// const user = await this.userService.findById(dto.userId);
// if (!user) {
// throw new NotFoundException(`User with ID ${dto.userId} not found.`);
// }
// }
if (!user) {
throw new NotFoundException(`User not found`);
}
@@ -79,14 +78,15 @@ export class OrderService {
if (!type) {
throw new NotFoundException(`Order type with ID ${dto.typeId} not found.`);
}
const product = invoiceItem.product
let product: Product | null = null;
if (dto.productId) {
product = await this.em.findOne(Product, { id: dto.productId });
if (!product) {
throw new NotFoundException(`Product with ID ${dto.productId} not found.`);
}
}
// let product: Product | null = null;
// product = await this.em.findOne(Product, { id: productId });
// if (!product) {
// throw new NotFoundException(`Product with ID ${dto.productId} not found.`);
// }
// if (dto.productId) {
// }
const order = this.em.create(Order, {
user,
@@ -145,13 +145,13 @@ export class OrderService {
async updateOrderAsAdmin(id: string, dto: UpdateOrderAsAdminDto): Promise<Order> {
const order = await this.findOrderOrFail(id);
if (dto.userId !== undefined) {
const user = await this.userService.findById(dto.userId);
if (!user) {
throw new NotFoundException(`User with ID ${dto.userId} not found.`);
}
order.user = user as User;
}
// if (dto.userId !== undefined) {
// const user = await this.userService.findById(dto.userId);
// if (!user) {
// throw new NotFoundException(`User with ID ${dto.userId} not found.`);
// }
// order.user = user as User;
// }
if (dto.typeId !== undefined) {
const type = await this.em.findOne(Category, { id: dto.typeId });
if (!type) {
@@ -165,17 +165,17 @@ export class OrderService {
if (dto.title !== undefined) {
order.title = dto.title;
}
if (dto.productId !== undefined) {
if (dto.productId == null || dto.productId === '') {
order.product = null;
} else {
const product = await this.em.findOne(Product, { id: dto.productId });
if (!product) {
throw new NotFoundException(`Product with ID ${dto.productId} not found.`);
}
order.product = product;
}
}
// if (dto.productId !== undefined) {
// if (dto.productId == null || dto.productId === '') {
// order.product = null;
// } else {
// const product = await this.em.findOne(Product, { id: dto.productId });
// if (!product) {
// throw new NotFoundException(`Product with ID ${dto.productId} not found.`);
// }
// order.product = product;
// }
// }
await this.em.flush();
return order;