update
This commit is contained in:
@@ -10,15 +10,14 @@ import { IAttachment } from '../interface/order.interface';
|
|||||||
|
|
||||||
|
|
||||||
export class CreateOrderAsAdminDto {
|
export class CreateOrderAsAdminDto {
|
||||||
@ApiPropertyOptional({ example: '' })
|
// @ApiPropertyOptional({ example: '' })
|
||||||
@IsString()
|
// @IsString()
|
||||||
@IsNotEmpty()
|
// @IsNotEmpty()
|
||||||
userId?: string;
|
// userId?: string;
|
||||||
|
|
||||||
@ApiPropertyOptional({ example: '' })
|
@ApiProperty({ example: '' })
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsNotEmpty()
|
invoiceItemId: string;
|
||||||
invoiceItemId?: string;
|
|
||||||
|
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
@IsString()
|
@IsString()
|
||||||
@@ -29,10 +28,10 @@ export class CreateOrderAsAdminDto {
|
|||||||
@IsInt()
|
@IsInt()
|
||||||
estimatedDays: number;
|
estimatedDays: number;
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
// @ApiPropertyOptional()
|
||||||
@IsOptional()
|
// @IsOptional()
|
||||||
@IsString()
|
// @IsString()
|
||||||
productId?: string;
|
// productId?: string;
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
@ApiPropertyOptional()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
|
|||||||
@@ -48,27 +48,26 @@ export class OrderService {
|
|||||||
let invoiceItem: null | InvoiceItem = null
|
let invoiceItem: null | InvoiceItem = null
|
||||||
let user: User | null = null
|
let user: User | null = null
|
||||||
|
|
||||||
if (dto.invoiceItemId) {
|
invoiceItem = await this.em.findOne(InvoiceItem, { id: dto.invoiceItemId }, { populate: ['invoice', 'invoice.user','product'] });
|
||||||
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
|
|
||||||
}
|
|
||||||
if (!invoiceItem) {
|
if (!invoiceItem) {
|
||||||
|
throw new NotFoundException(`Invoice item with ID ${dto.invoiceItemId} not found.`);
|
||||||
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.`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
if (!user) {
|
||||||
throw new NotFoundException(`User not found`);
|
throw new NotFoundException(`User not found`);
|
||||||
}
|
}
|
||||||
@@ -79,14 +78,15 @@ export class OrderService {
|
|||||||
if (!type) {
|
if (!type) {
|
||||||
throw new NotFoundException(`Order type with ID ${dto.typeId} not found.`);
|
throw new NotFoundException(`Order type with ID ${dto.typeId} not found.`);
|
||||||
}
|
}
|
||||||
|
const product = invoiceItem.product
|
||||||
|
|
||||||
let product: Product | null = null;
|
// let product: Product | null = null;
|
||||||
if (dto.productId) {
|
// product = await this.em.findOne(Product, { id: productId });
|
||||||
product = await this.em.findOne(Product, { id: dto.productId });
|
// if (!product) {
|
||||||
if (!product) {
|
// throw new NotFoundException(`Product with ID ${dto.productId} not found.`);
|
||||||
throw new NotFoundException(`Product with ID ${dto.productId} not found.`);
|
// }
|
||||||
}
|
// if (dto.productId) {
|
||||||
}
|
// }
|
||||||
|
|
||||||
const order = this.em.create(Order, {
|
const order = this.em.create(Order, {
|
||||||
user,
|
user,
|
||||||
@@ -145,13 +145,13 @@ export class OrderService {
|
|||||||
async updateOrderAsAdmin(id: string, dto: UpdateOrderAsAdminDto): Promise<Order> {
|
async updateOrderAsAdmin(id: string, dto: UpdateOrderAsAdminDto): Promise<Order> {
|
||||||
const order = await this.findOrderOrFail(id);
|
const order = await this.findOrderOrFail(id);
|
||||||
|
|
||||||
if (dto.userId !== undefined) {
|
// if (dto.userId !== undefined) {
|
||||||
const user = await this.userService.findById(dto.userId);
|
// const user = await this.userService.findById(dto.userId);
|
||||||
if (!user) {
|
// if (!user) {
|
||||||
throw new NotFoundException(`User with ID ${dto.userId} not found.`);
|
// throw new NotFoundException(`User with ID ${dto.userId} not found.`);
|
||||||
}
|
// }
|
||||||
order.user = user as User;
|
// order.user = user as User;
|
||||||
}
|
// }
|
||||||
if (dto.typeId !== undefined) {
|
if (dto.typeId !== undefined) {
|
||||||
const type = await this.em.findOne(Category, { id: dto.typeId });
|
const type = await this.em.findOne(Category, { id: dto.typeId });
|
||||||
if (!type) {
|
if (!type) {
|
||||||
@@ -165,17 +165,17 @@ export class OrderService {
|
|||||||
if (dto.title !== undefined) {
|
if (dto.title !== undefined) {
|
||||||
order.title = dto.title;
|
order.title = dto.title;
|
||||||
}
|
}
|
||||||
if (dto.productId !== undefined) {
|
// if (dto.productId !== undefined) {
|
||||||
if (dto.productId == null || dto.productId === '') {
|
// if (dto.productId == null || dto.productId === '') {
|
||||||
order.product = null;
|
// order.product = null;
|
||||||
} else {
|
// } else {
|
||||||
const product = await this.em.findOne(Product, { id: dto.productId });
|
// const product = await this.em.findOne(Product, { id: dto.productId });
|
||||||
if (!product) {
|
// if (!product) {
|
||||||
throw new NotFoundException(`Product with ID ${dto.productId} not found.`);
|
// throw new NotFoundException(`Product with ID ${dto.productId} not found.`);
|
||||||
}
|
// }
|
||||||
order.product = product;
|
// order.product = product;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
await this.em.flush();
|
await this.em.flush();
|
||||||
return order;
|
return order;
|
||||||
|
|||||||
Reference in New Issue
Block a user