order print
This commit is contained in:
@@ -43,16 +43,7 @@ export class CreateOrderAsAdminDto {
|
|||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsArray()
|
@IsArray()
|
||||||
attachments: IAttachment[];
|
attachments: IAttachment[];
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CreateOrderItemDtoAsAdmin {
|
|
||||||
@ApiProperty()
|
|
||||||
@IsString()
|
|
||||||
@IsNotEmpty()
|
|
||||||
productId: string;
|
|
||||||
|
|
||||||
@ApiPropertyOptional()
|
|
||||||
@IsOptional()
|
|
||||||
@IsInt()
|
|
||||||
quantity?: number;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,15 +1,8 @@
|
|||||||
import { ApiProperty, ApiPropertyOptional, PartialType } from '@nestjs/swagger';
|
import { PartialType } from '@nestjs/swagger';
|
||||||
import { CreateOrderAsAdminDto, CreateOrderItemDtoAsAdmin } from './create-order.dto';
|
import { CreateOrderAsAdminDto } from './create-order.dto';
|
||||||
import { IsOptional, IsString } from 'class-validator';
|
|
||||||
|
|
||||||
export class UpdateOrCreateOrderItem extends CreateOrderItemDtoAsAdmin {
|
|
||||||
@ApiProperty()
|
|
||||||
@IsString()
|
|
||||||
id: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class UpdateOrderAsAdminDto extends PartialType(CreateOrderAsAdminDto) {
|
export class UpdateOrderAsAdminDto extends PartialType(CreateOrderAsAdminDto) {
|
||||||
@ApiPropertyOptional({ type: [UpdateOrCreateOrderItem] })
|
|
||||||
@IsOptional()
|
|
||||||
items?: UpdateOrCreateOrderItem[];
|
|
||||||
}
|
}
|
||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
Enum,
|
Enum,
|
||||||
PrimaryKey,
|
PrimaryKey,
|
||||||
OptionalProps,
|
OptionalProps,
|
||||||
|
OneToOne
|
||||||
} from '@mikro-orm/core';
|
} from '@mikro-orm/core';
|
||||||
import { User } from '../../user/entities/user.entity';
|
import { User } from '../../user/entities/user.entity';
|
||||||
import { ulid } from 'ulid';
|
import { ulid } from 'ulid';
|
||||||
@@ -13,9 +14,9 @@ import { Admin } from 'src/modules/admin/entities/admin.entity';
|
|||||||
import { BaseEntity } from 'src/common/entities/base.entity';
|
import { BaseEntity } from 'src/common/entities/base.entity';
|
||||||
import { IAttachment, OrderStatusEnum } from '../interface/order.interface';
|
import { IAttachment, OrderStatusEnum } from '../interface/order.interface';
|
||||||
import { InvoiceItem } from 'src/modules/invoice/entities/invoice-item.entity';
|
import { InvoiceItem } from 'src/modules/invoice/entities/invoice-item.entity';
|
||||||
import { IField } from 'src/modules/request/interface/request.interface';
|
|
||||||
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 { Category } from 'src/modules/product/entities/category.entity';
|
||||||
|
import { OrderPrint } from './print.entity';
|
||||||
|
|
||||||
@Entity({ tableName: 'orders' })
|
@Entity({ tableName: 'orders' })
|
||||||
@Index({ properties: ['user'] })
|
@Index({ properties: ['user'] })
|
||||||
@@ -28,6 +29,10 @@ export class Order extends BaseEntity {
|
|||||||
@ManyToOne(() => Product, { nullable: true })
|
@ManyToOne(() => Product, { nullable: true })
|
||||||
product?: Product | null;
|
product?: Product | null;
|
||||||
|
|
||||||
|
|
||||||
|
@OneToOne(() => OrderPrint, (orderPrint) => orderPrint.order, { owner: true, nullable: true })
|
||||||
|
print?: OrderPrint | null
|
||||||
|
|
||||||
@PrimaryKey({ type: 'string', columnType: 'char(26)' })
|
@PrimaryKey({ type: 'string', columnType: 'char(26)' })
|
||||||
id: string = ulid()
|
id: string = ulid()
|
||||||
|
|
||||||
@@ -52,8 +57,6 @@ export class Order extends BaseEntity {
|
|||||||
})
|
})
|
||||||
orderNumber: number;
|
orderNumber: number;
|
||||||
|
|
||||||
@Property({ type: 'json', nullable: true })
|
|
||||||
attributes?: IField[] // print form selected attributes
|
|
||||||
|
|
||||||
@Enum(() => OrderStatusEnum)
|
@Enum(() => OrderStatusEnum)
|
||||||
status: OrderStatusEnum = OrderStatusEnum.CREATED;
|
status: OrderStatusEnum = OrderStatusEnum.CREATED;
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import { Entity, Property, OptionalProps, OneToOne } from '@mikro-orm/core';
|
||||||
|
import { BaseEntity } from 'src/common/entities/base.entity';
|
||||||
|
import { IField } from 'src/modules/request/interface/request.interface';
|
||||||
|
import { Order } from './order.entity';
|
||||||
|
|
||||||
|
|
||||||
|
@Entity({ tableName: 'prints' })
|
||||||
|
export class OrderPrint extends BaseEntity {
|
||||||
|
[OptionalProps]?: 'createdAt' | 'deletedAt'
|
||||||
|
|
||||||
|
@Property({ type: 'json', nullable: true })
|
||||||
|
attributes?: IField[]
|
||||||
|
|
||||||
|
|
||||||
|
@OneToOne(() => Order, (order) => order.print, { mappedBy: 'print' })
|
||||||
|
order!: Order
|
||||||
|
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ import { MikroOrmModule } from '@mikro-orm/nestjs';
|
|||||||
import { OrderService } from './providers/order.service';
|
import { OrderService } from './providers/order.service';
|
||||||
import { OrderController } from './controllers/order.controller';
|
import { OrderController } from './controllers/order.controller';
|
||||||
import { Order } from './entities/order.entity';
|
import { Order } from './entities/order.entity';
|
||||||
|
import { OrderPrint } from './entities/print.entity';
|
||||||
import { AuthModule } from '../auth/auth.module';
|
import { AuthModule } from '../auth/auth.module';
|
||||||
import { PaymentModule } from '../payment/payments.module';
|
import { PaymentModule } from '../payment/payments.module';
|
||||||
import { JwtModule } from '@nestjs/jwt';
|
import { JwtModule } from '@nestjs/jwt';
|
||||||
@@ -18,7 +19,7 @@ import { TicketModule } from '../ticket/ticket.module';
|
|||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
MikroOrmModule.forFeature([Order]),
|
MikroOrmModule.forFeature([Order, OrderPrint]),
|
||||||
AuthModule,
|
AuthModule,
|
||||||
forwardRef(() => PaymentModule),
|
forwardRef(() => PaymentModule),
|
||||||
JwtModule,
|
JwtModule,
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import { FindOrdersDto } from '../dto/find-orders.dto';
|
|||||||
import { EventEmitter2 } from '@nestjs/event-emitter';
|
import { EventEmitter2 } from '@nestjs/event-emitter';
|
||||||
import {
|
import {
|
||||||
CreateOrderAsAdminDto,
|
CreateOrderAsAdminDto,
|
||||||
CreateOrderItemDtoAsAdmin,
|
|
||||||
} from '../dto/create-order.dto';
|
} 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';
|
||||||
@@ -101,7 +100,8 @@ export class OrderService {
|
|||||||
status: OrderStatusEnum.CREATED,
|
status: OrderStatusEnum.CREATED,
|
||||||
estimatedDays: dto.estimatedDays,
|
estimatedDays: dto.estimatedDays,
|
||||||
invoiceItem,
|
invoiceItem,
|
||||||
attachments: dto.attachments
|
attachments: dto.attachments,
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
await this.em.persistAndFlush(order);
|
await this.em.persistAndFlush(order);
|
||||||
|
|||||||
Reference in New Issue
Block a user