update
This commit is contained in:
@@ -10,15 +10,14 @@ import { IAttachment } from '../interface/order.interface';
|
||||
|
||||
|
||||
export class CreateOrderAsAdminDto {
|
||||
@ApiPropertyOptional({ example: '' })
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
userId?: string;
|
||||
// @ApiPropertyOptional({ example: '' })
|
||||
// @IsString()
|
||||
// @IsNotEmpty()
|
||||
// userId?: string;
|
||||
|
||||
@ApiPropertyOptional({ example: '' })
|
||||
@ApiProperty({ example: '' })
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
invoiceItemId?: string;
|
||||
invoiceItemId: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
@@ -29,10 +28,10 @@ export class CreateOrderAsAdminDto {
|
||||
@IsInt()
|
||||
estimatedDays: number;
|
||||
|
||||
@ApiPropertyOptional()
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
productId?: string;
|
||||
// @ApiPropertyOptional()
|
||||
// @IsOptional()
|
||||
// @IsString()
|
||||
// productId?: string;
|
||||
|
||||
@ApiPropertyOptional()
|
||||
@IsOptional()
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user