update
This commit is contained in:
@@ -10,14 +10,15 @@ import { IAttachment } from '../interface/order.interface';
|
|||||||
|
|
||||||
|
|
||||||
export class CreateOrderAsAdminDto {
|
export class CreateOrderAsAdminDto {
|
||||||
// @ApiPropertyOptional({ example: '' })
|
@ApiPropertyOptional({ example: '' })
|
||||||
// @IsString()
|
|
||||||
// @IsNotEmpty()
|
|
||||||
// userId?: string;
|
|
||||||
|
|
||||||
@ApiProperty({ example: '' })
|
|
||||||
@IsString()
|
@IsString()
|
||||||
invoiceItemId: string;
|
@IsNotEmpty()
|
||||||
|
userId?: string;
|
||||||
|
|
||||||
|
@ApiPropertyOptional({ example: '' })
|
||||||
|
@IsString()
|
||||||
|
@IsOptional()
|
||||||
|
invoiceItemId?: string;
|
||||||
|
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
@IsString()
|
@IsString()
|
||||||
@@ -28,10 +29,10 @@ export class CreateOrderAsAdminDto {
|
|||||||
@IsInt()
|
@IsInt()
|
||||||
estimatedDays: number;
|
estimatedDays: number;
|
||||||
|
|
||||||
// @ApiPropertyOptional()
|
@ApiPropertyOptional()
|
||||||
// @IsOptional()
|
@IsOptional()
|
||||||
// @IsString()
|
@IsString()
|
||||||
// productId?: string;
|
productId?: string;
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
@ApiPropertyOptional()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
|
|||||||
@@ -64,10 +64,5 @@ export class Order extends BaseEntity {
|
|||||||
@Property({ type: 'json' })
|
@Property({ type: 'json' })
|
||||||
attachments: IAttachment[] = []
|
attachments: IAttachment[] = []
|
||||||
|
|
||||||
@Property({ type: 'string', nullable: true })
|
|
||||||
printery?: string
|
|
||||||
|
|
||||||
@Property({ type: 'string', nullable: true })
|
|
||||||
Lithography?: string
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,10 @@ import { EntityManager } from '@mikro-orm/postgresql';
|
|||||||
import { OrderRepository } from '../repositories/order.repository';
|
import { OrderRepository } from '../repositories/order.repository';
|
||||||
import { FindOrdersDto } from '../dto/find-orders.dto';
|
import { FindOrdersDto } from '../dto/find-orders.dto';
|
||||||
import { EventEmitter2 } from '@nestjs/event-emitter';
|
import { EventEmitter2 } from '@nestjs/event-emitter';
|
||||||
import { CreateOrderAsAdminDto } from '../dto/create-order.dto';
|
import {
|
||||||
|
CreateOrderAsAdminDto,
|
||||||
|
CreateOrderItemDtoAsAdmin,
|
||||||
|
} from '../dto/create-order.dto';
|
||||||
import { UserService } from 'src/modules/user/providers/user.service';
|
import { UserService } from 'src/modules/user/providers/user.service';
|
||||||
import { OrderStatusEnum } from '../interface/order.interface';
|
import { OrderStatusEnum } from '../interface/order.interface';
|
||||||
import { ProductService } from 'src/modules/product/providers/product.service';
|
import { ProductService } from 'src/modules/product/providers/product.service';
|
||||||
@@ -15,15 +18,16 @@ import { Order } from '../entities/order.entity';
|
|||||||
import { PaymentRepository } from 'src/modules/payment/repositories/payment.repository';
|
import { PaymentRepository } from 'src/modules/payment/repositories/payment.repository';
|
||||||
import { AdminService } from 'src/modules/admin/providers/admin.service';
|
import { AdminService } from 'src/modules/admin/providers/admin.service';
|
||||||
import { UpdateOrderAsAdminDto } from '../dto/update-order.dto';
|
import { UpdateOrderAsAdminDto } from '../dto/update-order.dto';
|
||||||
|
import { FindOrderItemsDto } from '../dto/find-order-items.dto';
|
||||||
import { PermissionService } from 'src/modules/roles/providers/permissions.service';
|
import { PermissionService } from 'src/modules/roles/providers/permissions.service';
|
||||||
import { PermissionEnum } from 'src/common/enums/permission.enum';
|
import { PermissionEnum } from 'src/common/enums/permission.enum';
|
||||||
import { User } from 'src/modules/user/entities/user.entity';
|
import { User } from 'src/modules/user/entities/user.entity';
|
||||||
import { Product } from 'src/modules/product/entities/product.entity';
|
import { Product } from 'src/modules/product/entities/product.entity';
|
||||||
|
import { Category } from 'src/modules/product/entities/category.entity';
|
||||||
import { InvoiceItem } from 'src/modules/invoice/entities/invoice-item.entity';
|
import { InvoiceItem } from 'src/modules/invoice/entities/invoice-item.entity';
|
||||||
import { PaginatedResult } from 'src/common/interfaces/pagination.interface';
|
import { PaginatedResult } from 'src/common/interfaces/pagination.interface';
|
||||||
import { UpdateStatusAsDesignerDto } from '../dto/update-status-as-designer.dto';
|
import { UpdateStatusAsDesignerDto } from '../dto/update-status-as-designer.dto';
|
||||||
import { UpdateStatusDto } from '../dto/update-status.dto';
|
import { UpdateStatusDto } from '../dto/update-status.dto';
|
||||||
import { Category } from 'src/modules/product/entities/category.entity';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class OrderService {
|
export class OrderService {
|
||||||
@@ -48,25 +52,26 @@ export class OrderService {
|
|||||||
let invoiceItem: null | InvoiceItem = null
|
let invoiceItem: null | InvoiceItem = null
|
||||||
let user: User | null = null
|
let user: User | null = null
|
||||||
|
|
||||||
invoiceItem = await this.em.findOne(InvoiceItem, { id: dto.invoiceItemId }, { populate: ['invoice', 'invoice.user','product'] });
|
if (dto.invoiceItemId) {
|
||||||
if (!invoiceItem) {
|
invoiceItem = await this.em.findOne(InvoiceItem, { id: dto.invoiceItemId }, { populate: ['invoice', 'invoice.user'] });
|
||||||
throw new NotFoundException(`Invoice item with ID ${dto.invoiceItemId} not found.`);
|
if (!invoiceItem) {
|
||||||
|
throw new NotFoundException(`Invoice item with ID ${dto.invoiceItemId} not found.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
user = invoiceItem.invoice.user
|
||||||
}
|
}
|
||||||
|
if (!invoiceItem) {
|
||||||
|
|
||||||
user = invoiceItem.invoice.user
|
if (!dto.userId) {
|
||||||
|
throw new NotFoundException(`UserId is mandatory`);
|
||||||
|
}
|
||||||
|
|
||||||
// if (!invoiceItem) {
|
const user = await this.userService.findById(dto.userId);
|
||||||
|
|
||||||
// if (!dto.userId) {
|
if (!user) {
|
||||||
// throw new NotFoundException(`UserId is mandatory`);
|
throw new NotFoundException(`User with ID ${dto.userId} not found.`);
|
||||||
// }
|
}
|
||||||
|
}
|
||||||
// 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`);
|
||||||
@@ -78,15 +83,14 @@ 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;
|
||||||
// product = await this.em.findOne(Product, { id: productId });
|
if (dto.productId) {
|
||||||
// if (!product) {
|
product = await this.em.findOne(Product, { id: dto.productId });
|
||||||
// throw new NotFoundException(`Product with ID ${dto.productId} not found.`);
|
if (!product) {
|
||||||
// }
|
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 +149,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 +169,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