diff --git a/backend/src/cart/cart-entity.interface.ts b/backend/src/cart/cart-entity.interface.ts index b996d340..473cfd8b 100644 --- a/backend/src/cart/cart-entity.interface.ts +++ b/backend/src/cart/cart-entity.interface.ts @@ -6,6 +6,6 @@ export interface ICartItem { menuId: Types.ObjectId; orderId: Types.ObjectId; total: number; - selectedItems: SelectedCartItem[]; + selectedItems?: SelectedCartItem[]; audit: Audit; } diff --git a/backend/src/cart/cart-item.ts b/backend/src/cart/cart-item.ts index e35f7c0a..9b06f870 100644 --- a/backend/src/cart/cart-item.ts +++ b/backend/src/cart/cart-item.ts @@ -7,7 +7,7 @@ export class CartItem extends Entity implements ICartItem { _menuId: Types.ObjectId; _orderId: Types.ObjectId; _total: number; - _selectedItems: SelectedCartItem[]; + _selectedItems: SelectedCartItem[] | undefined; _audit: Audit; constructor(id: Types.ObjectId, props: ICartItem) { @@ -42,11 +42,11 @@ export class CartItem extends Entity implements ICartItem { this._total = total; } - get selectedItems(): SelectedCartItem[] { + get selectedItems(): SelectedCartItem[] | undefined { return this._selectedItems; } - set setSelectedItems(selectedItems: SelectedCartItem[]) { + set setSelectedItems(selectedItems: SelectedCartItem[] | undefined) { this._selectedItems = selectedItems; } diff --git a/backend/src/cart/selectedItems/selected-cart-item.mapper.ts b/backend/src/cart/selectedItems/selected-cart-item.mapper.ts index 20b19ab4..7cb2b743 100644 --- a/backend/src/cart/selectedItems/selected-cart-item.mapper.ts +++ b/backend/src/cart/selectedItems/selected-cart-item.mapper.ts @@ -6,7 +6,7 @@ import { SelectedCartItem } from './selectedCartItem'; export class SelectedCartItemMapper implements IMapper { constructor(private readonly auditMapper: AuditMapper) {} toPersistence(entity: SelectedCartItem): SelectedCartItemDataModel { - const { id, menuId, itemId, price, quantity, audit } = entity; + const { id, cartItemId, itemId, price, quantity, audit } = entity; const { auditCreatedBy, auditCreatedDateTime, @@ -17,7 +17,7 @@ export class SelectedCartItemMapper implements IMapper implements ISelectedCartItem { - _menuId: Types.ObjectId; + _cartItemId: Types.ObjectId; _itemId: Types.ObjectId; _price: number; _quantity: number; @@ -11,19 +11,19 @@ export class SelectedCartItem extends Entity implements ISele constructor(id: Types.ObjectId, props: ISelectedCartItem) { super(id); - this._menuId = props.menuId; + this._cartItemId = props.cartItemId; this._price = props.price; this._quantity = props.quantity; this._itemId = props.itemId; this._audit = props.audit; } - get menuId(): Types.ObjectId { - return this._menuId; + get cartItemId(): Types.ObjectId { + return this._cartItemId; } - set menuId(id: Types.ObjectId) { - this._menuId = id; + set cartItemId(id: Types.ObjectId) { + this._cartItemId = id; } get itemId(): Types.ObjectId { diff --git a/backend/src/infrastructure/data_access/repositories/models/cart-item-data.model.ts b/backend/src/infrastructure/data_access/repositories/models/cart-item-data.model.ts index c33bdf81..3ed81007 100644 --- a/backend/src/infrastructure/data_access/repositories/models/cart-item-data.model.ts +++ b/backend/src/infrastructure/data_access/repositories/models/cart-item-data.model.ts @@ -5,5 +5,5 @@ export interface ICartItemModel { readonly menuId: Types.ObjectId; readonly orderId: Types.ObjectId; readonly total: number; - readonly selectedItems: SelectedCartItemDataModel[]; + readonly selectedItems?: SelectedCartItemDataModel[]; } diff --git a/backend/src/infrastructure/data_access/repositories/models/order-model.interface.ts b/backend/src/infrastructure/data_access/repositories/models/order-model.interface.ts index daafe39b..3d27734f 100644 --- a/backend/src/infrastructure/data_access/repositories/models/order-model.interface.ts +++ b/backend/src/infrastructure/data_access/repositories/models/order-model.interface.ts @@ -10,5 +10,5 @@ export interface IOrderDataModel { readonly total: number; readonly discount?: number; readonly orderManagerId?: Types.ObjectId; - readonly cartItems: CartItemDataModel[]; + readonly cartItems?: CartItemDataModel[]; } diff --git a/backend/src/infrastructure/data_access/repositories/models/selected-item-model.interface.ts b/backend/src/infrastructure/data_access/repositories/models/selected-item-model.interface.ts index d54a7c59..4a792efb 100644 --- a/backend/src/infrastructure/data_access/repositories/models/selected-item-model.interface.ts +++ b/backend/src/infrastructure/data_access/repositories/models/selected-item-model.interface.ts @@ -1,8 +1,7 @@ import { Types } from 'mongoose'; export interface ISelectedCartItemDataModel { - readonly menuId: Types.ObjectId; - readonly itemId: Types.ObjectId; + readonly cartItemId: Types.ObjectId; readonly price: number; readonly quantity: number; } diff --git a/backend/src/infrastructure/data_access/repositories/schemas/cartItem.schema.ts b/backend/src/infrastructure/data_access/repositories/schemas/cartItem.schema.ts index 883c526f..1d662bb3 100644 --- a/backend/src/infrastructure/data_access/repositories/schemas/cartItem.schema.ts +++ b/backend/src/infrastructure/data_access/repositories/schemas/cartItem.schema.ts @@ -23,7 +23,7 @@ export class CartItemDataModel extends BaseDocument implements ICartItemModel { @Prop({ type: [{ type: mongoose.Schema.Types.ObjectId, ref: SelectedCartItemDataModel }] }) @Type(() => SelectedCartItemDataModel) - selectedItems: SelectedCartItemDataModel[]; + selectedItems?: SelectedCartItemDataModel[]; } export const CartItemSchema = SchemaFactory.createForClass(CartItemDataModel); diff --git a/backend/src/infrastructure/data_access/repositories/schemas/order.schema.ts b/backend/src/infrastructure/data_access/repositories/schemas/order.schema.ts index c7562f2c..0a0fffe5 100644 --- a/backend/src/infrastructure/data_access/repositories/schemas/order.schema.ts +++ b/backend/src/infrastructure/data_access/repositories/schemas/order.schema.ts @@ -34,7 +34,7 @@ export class OrderDataModel extends BaseDocument implements IOrderDataModel { @Prop({ type: [{ type: mongoose.Schema.Types.ObjectId, ref: CartItemDataModel }] }) @Type(() => CartItemDataModel) - cartItems: CartItemDataModel[]; + cartItems?: CartItemDataModel[]; } export const OrderSchema = SchemaFactory.createForClass(OrderDataModel); diff --git a/backend/src/infrastructure/data_access/repositories/schemas/selected-cart-item.schema.ts b/backend/src/infrastructure/data_access/repositories/schemas/selected-cart-item.schema.ts index be0f488f..0c6cfce9 100644 --- a/backend/src/infrastructure/data_access/repositories/schemas/selected-cart-item.schema.ts +++ b/backend/src/infrastructure/data_access/repositories/schemas/selected-cart-item.schema.ts @@ -1,22 +1,22 @@ -import { BaseDocument } from 'src/infrastructure/database'; -import { ISelectedCartItemDataModel } from '../models/selected-item-model.interface'; import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; -import mongoose, { Types } from 'mongoose'; import { Type } from 'class-transformer'; -import { MenuDataModel } from './menu.schema'; +import mongoose, { Types } from 'mongoose'; +import { BaseDocument } from 'src/infrastructure/database'; +import { ISelectedCartItemDataModel } from '../models/selected-item-model.interface'; import { CartItemDataModel } from './cartItem.schema'; +import { ItemDataModel } from './item.schema'; export type SelectedCartItemDocument = SelectedCartItemDataModel & Document; @Schema({ versionKey: 'false' }) export class SelectedCartItemDataModel extends BaseDocument implements ISelectedCartItemDataModel { @Prop({ type: mongoose.Schema.Types.ObjectId }) - @Type(() => MenuDataModel) - menuId: Types.ObjectId; + @Type(() => ItemDataModel) + itemId: Types.ObjectId; @Prop({ type: mongoose.Schema.Types.ObjectId }) @Type(() => CartItemDataModel) - itemId: Types.ObjectId; + cartItemId: Types.ObjectId; @Prop({ type: Number, required: true }) price: number; diff --git a/backend/src/order/order-entity.interface.ts b/backend/src/order/order-entity.interface.ts index a2798ab6..1dc06cd6 100644 --- a/backend/src/order/order-entity.interface.ts +++ b/backend/src/order/order-entity.interface.ts @@ -14,5 +14,5 @@ export interface IOrder { discount?: number; orderManagerId?: Types.ObjectId; audit: Audit; - cartItems: CartItem[]; + cartItems?: CartItem[]; } diff --git a/backend/src/order/order.ts b/backend/src/order/order.ts index f4554bd6..c93d7dd5 100644 --- a/backend/src/order/order.ts +++ b/backend/src/order/order.ts @@ -13,7 +13,7 @@ export class Order extends Entity implements IOrder { _discount?: number; _orderManagerId: Types.ObjectId; _audit: Audit; - _cartItems: CartItem[]; + _cartItems: CartItem[] | undefined; constructor( id: Types.ObjectId, @@ -95,11 +95,11 @@ export class Order extends Entity implements IOrder { this._audit = audit; } - get cartItems() { + get cartItems(): CartItem[] | undefined { return this._cartItems; } - set cartItems(cartItems: CartItem[]) { + set cartItems(cartItems: CartItem[] | undefined) { this._cartItems = cartItems; }