update entity
This commit is contained in:
@@ -2,7 +2,7 @@ import { Entity, Enum, Index, ManyToOne, OneToMany, PrimaryKey, Property } from
|
|||||||
import { BaseEntity } from '../../../common/entities/base.entity';
|
import { BaseEntity } from '../../../common/entities/base.entity';
|
||||||
import { Order } from './order.entity';
|
import { Order } from './order.entity';
|
||||||
import { Product } from 'src/modules/product/entities/product.entity';
|
import { Product } from 'src/modules/product/entities/product.entity';
|
||||||
import { OrderItemStatus } from '../interface/order.interface';
|
// import { OrderItemStatus } from '../interface/order.interface';
|
||||||
|
|
||||||
@Entity({ tableName: 'order_items' })
|
@Entity({ tableName: 'order_items' })
|
||||||
@Index({ properties: ['order'] })
|
@Index({ properties: ['order'] })
|
||||||
@@ -38,6 +38,8 @@ export class OrderItem extends BaseEntity {
|
|||||||
@Property({ nullable: true })
|
@Property({ nullable: true })
|
||||||
description?: string;
|
description?: string;
|
||||||
|
|
||||||
@Enum(() => OrderItemStatus)
|
// @Enum(() => OrderItemStatus)
|
||||||
status!: OrderItemStatus;
|
// status!: OrderItemStatus;
|
||||||
|
@Property({ nullable: true, columnType: 'timestamptz' })
|
||||||
|
confirmedAt?: Date;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ export class Order extends BaseEntity {
|
|||||||
@PrimaryKey({ type: 'string', columnType: 'char(26)' })
|
@PrimaryKey({ type: 'string', columnType: 'char(26)' })
|
||||||
id: string = ulid()
|
id: string = ulid()
|
||||||
|
|
||||||
|
//TODO : need a new field for confirmation .confirmedAt
|
||||||
|
// also need another for
|
||||||
|
|
||||||
@ManyToOne(() => User)
|
@ManyToOne(() => User)
|
||||||
user!: User;
|
user!: User;
|
||||||
|
|
||||||
@@ -80,7 +83,7 @@ export class Order extends BaseEntity {
|
|||||||
balance!: number;
|
balance!: number;
|
||||||
|
|
||||||
@Property({ type: 'decimal', precision: 10, scale: 0, nullable: true })
|
@Property({ type: 'decimal', precision: 10, scale: 0, nullable: true })
|
||||||
dueDate?: number;
|
dueDate?: number; // number of days to be done
|
||||||
// get balance(): number {
|
// get balance(): number {
|
||||||
// return this._balance
|
// return this._balance
|
||||||
// }
|
// }
|
||||||
@@ -94,14 +97,14 @@ export class Order extends BaseEntity {
|
|||||||
@Enum(() => OrderStatusEnum)
|
@Enum(() => OrderStatusEnum)
|
||||||
status!: OrderStatusEnum;
|
status!: OrderStatusEnum;
|
||||||
|
|
||||||
@Property({ nullable: true, columnType: 'timestamptz' })
|
// @Property({ nullable: true, columnType: 'timestamptz' })
|
||||||
confirmedAt?: Date;
|
// confirmedAt?: Date;
|
||||||
|
|
||||||
@Property({ type: 'json', nullable: true })
|
@Property({ type: 'json', nullable: true })
|
||||||
attachments?: string[]
|
attachments?: string[]
|
||||||
|
|
||||||
@Property({ type: 'json', nullable: true })
|
@Property({ type: 'json', nullable: true })
|
||||||
printIds?: string[]
|
printIds?: string[] // id of field options
|
||||||
|
|
||||||
@Property({ type: 'string', nullable: true })
|
@Property({ type: 'string', nullable: true })
|
||||||
paymentMethod?: string;
|
paymentMethod?: string;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export enum OrderStatusEnum {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export enum OrderItemStatus {
|
// export enum OrderItemStatus {
|
||||||
PENDING = 'pending',
|
// PENDING = 'pending',
|
||||||
CONFIRMED = 'confirmed',
|
// CONFIRMED = 'confirmed',
|
||||||
}
|
// }
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { FindOrdersDto } from '../dto/find-orders.dto';
|
|||||||
import { EventEmitter2 } from '@nestjs/event-emitter';
|
import { EventEmitter2 } from '@nestjs/event-emitter';
|
||||||
import { CreateOrderDto } from '../dto/create-order.dto';
|
import { CreateOrderDto } from '../dto/create-order.dto';
|
||||||
import { UserService } from 'src/modules/user/providers/user.service';
|
import { UserService } from 'src/modules/user/providers/user.service';
|
||||||
import { OrderItemStatus, OrderStatusEnum } from '../interface/order.interface';
|
import { OrderStatusEnum } from '../interface/order.interface';
|
||||||
import { OrderItemRepository } from '../repositories/order-item.repository';
|
import { OrderItemRepository } from '../repositories/order-item.repository';
|
||||||
import { ProductService } from 'src/modules/product/providers/product.service';
|
import { ProductService } from 'src/modules/product/providers/product.service';
|
||||||
import { ProductRepository } from 'src/modules/product/repositories/product.repository';
|
import { ProductRepository } from 'src/modules/product/repositories/product.repository';
|
||||||
@@ -15,8 +15,7 @@ import { TicketRepository } from 'src/modules/ticket/repositories/tickets.reposi
|
|||||||
import { CreateInvoiceDto } from '../dto/create-invoice.dto';
|
import { CreateInvoiceDto } from '../dto/create-invoice.dto';
|
||||||
import { AdminRepository } from 'src/modules/admin/repositories/admin.repository';
|
import { AdminRepository } from 'src/modules/admin/repositories/admin.repository';
|
||||||
import { CreateOrderAsAdminDto } from '../dto/create-order-as-admin.dto';
|
import { CreateOrderAsAdminDto } from '../dto/create-order-as-admin.dto';
|
||||||
import { AddOrderItemDto } from '../dto/add-order-item.dto';
|
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class OrderService {
|
export class OrderService {
|
||||||
@@ -76,7 +75,6 @@ export class OrderService {
|
|||||||
attributesValues: item.attributesValues,
|
attributesValues: item.attributesValues,
|
||||||
product,
|
product,
|
||||||
quantity: item.quantity,
|
quantity: item.quantity,
|
||||||
status: OrderItemStatus.PENDING,
|
|
||||||
unitPrice: 0,
|
unitPrice: 0,
|
||||||
total: 0,
|
total: 0,
|
||||||
subTotal: 0,
|
subTotal: 0,
|
||||||
@@ -157,7 +155,6 @@ export class OrderService {
|
|||||||
attributesValues: item.attributesValues,
|
attributesValues: item.attributesValues,
|
||||||
product,
|
product,
|
||||||
quantity: item.quantity,
|
quantity: item.quantity,
|
||||||
status: OrderItemStatus.CONFIRMED,
|
|
||||||
unitPrice: item.unitPrice,
|
unitPrice: item.unitPrice,
|
||||||
total: item.unitPrice * item.quantity,
|
total: item.unitPrice * item.quantity,
|
||||||
discount: 0,
|
discount: 0,
|
||||||
@@ -251,7 +248,7 @@ export class OrderService {
|
|||||||
total: (item.unitPrice - item.discount) * item.quantity,
|
total: (item.unitPrice - item.discount) * item.quantity,
|
||||||
subTotal: item.unitPrice * item.quantity,
|
subTotal: item.unitPrice * item.quantity,
|
||||||
quantity: item.quantity,
|
quantity: item.quantity,
|
||||||
status: OrderItemStatus.CONFIRMED,
|
confirmedAt: new Date(),
|
||||||
attributesValues: item.attributesValues,
|
attributesValues: item.attributesValues,
|
||||||
order
|
order
|
||||||
})
|
})
|
||||||
@@ -305,7 +302,7 @@ export class OrderService {
|
|||||||
throw new BadRequestException("Order Item does not belong to you")
|
throw new BadRequestException("Order Item does not belong to you")
|
||||||
}
|
}
|
||||||
|
|
||||||
orderItem.status = OrderItemStatus.CONFIRMED
|
orderItem.confirmedAt = new Date()
|
||||||
|
|
||||||
await this.em.persistAndFlush(OrderItem)
|
await this.em.persistAndFlush(OrderItem)
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { IsString, IsOptional, IsBoolean, IsInt, Min, IsEnum, IsNotEmpty } from 'class-validator';
|
import { IsString, IsOptional, IsBoolean, IsInt, Min, IsEnum, IsNotEmpty } from 'class-validator';
|
||||||
import { ApiPropertyOptional, ApiProperty } from '@nestjs/swagger';
|
import { ApiPropertyOptional, ApiProperty } from '@nestjs/swagger';
|
||||||
import { Type } from 'class-transformer';
|
import { Type } from 'class-transformer';
|
||||||
import { AttributeType } from '../interface/product.interface';
|
import { FieldType } from 'src/modules/print/interface/print';
|
||||||
|
|
||||||
export class CreateAttributeDto {
|
export class CreateAttributeDto {
|
||||||
@IsString()
|
@IsString()
|
||||||
@@ -20,9 +20,9 @@ export class CreateAttributeDto {
|
|||||||
isRequired: boolean;
|
isRequired: boolean;
|
||||||
|
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
@IsEnum(AttributeType)
|
@IsEnum(FieldType)
|
||||||
@ApiProperty({ enum: AttributeType, example: AttributeType.SELECT })
|
@ApiProperty({ enum: FieldType, example: FieldType.select })
|
||||||
type: AttributeType;
|
type: FieldType;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsInt()
|
@IsInt()
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { Collection, Entity, Enum, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core';
|
import { Collection, Entity, Enum, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core';
|
||||||
import { BaseEntity } from '../../../common/entities/base.entity';
|
import { BaseEntity } from '../../../common/entities/base.entity';
|
||||||
import { AttributeType } from '../interface/product.interface';
|
import { Product } from './product.entity';
|
||||||
import { Product } from './product.entity';
|
|
||||||
import { AttributeValue } from './attribute-value.entity';
|
import { AttributeValue } from './attribute-value.entity';
|
||||||
|
import { FieldType } from 'src/modules/print/interface/print';
|
||||||
|
|
||||||
@Entity({ tableName: 'attributes' })
|
@Entity({ tableName: 'attributes' })
|
||||||
export class Attribute extends BaseEntity {
|
export class Attribute extends BaseEntity {
|
||||||
@@ -24,8 +24,8 @@ export class Attribute extends BaseEntity {
|
|||||||
@Property()
|
@Property()
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
@Enum(() => AttributeType)
|
@Enum(() => FieldType)
|
||||||
type: AttributeType;
|
type: FieldType;
|
||||||
|
|
||||||
@Property({ type: 'boolean', default: false })
|
@Property({ type: 'boolean', default: false })
|
||||||
isRequired: boolean = false;
|
isRequired: boolean = false;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
export enum AttributeType{
|
// export enum AttributeType{
|
||||||
SELECT='select',
|
// SELECT='select',
|
||||||
TEXT='text',
|
// TEXT='text',
|
||||||
NUMBER='number',
|
// NUMBER='number',
|
||||||
CHECKBOX='checkbox',
|
// CHECKBOX='checkbox',
|
||||||
BOOLEAN='boolean',
|
// BOOLEAN='boolean',
|
||||||
}
|
// }
|
||||||
|
|||||||
Reference in New Issue
Block a user