Skip to content

Commit

Permalink
Development (#482)
Browse files Browse the repository at this point in the history
* include restaurant information as part of the menu response (#471)

* include restaurant information as part of the menu response

* fix build errors

* fix build errors

---------

Co-authored-by: Olasunkanmi Oyinlola <olasunkanmioyinlola@Olasunkanmis-Mac-mini.local>

* 349 place order (#473)

* include restaurant information as part of the menu response

* fix build errors

* fix build errors

* fix the create order flow, from frontend to backend

---------

Co-authored-by: Olasunkanmi Oyinlola <olasunkanmioyinlola@Olasunkanmis-Mac-mini.local>

* 349 place order (#476)

* 349 place order (#478)

* include restaurant information as part of the menu response

* fix build errors

* fix build errors

* fix the create order flow, from frontend to backend

* place order, add success animation and clear local storage if the cart has been filled for an hr and more

* fix build errors

* fix build errors

* move the implementation of adding expiry to cart to addItemToCart handler

* fix issues with creating notes when none was passwd

* npm audit to upgrade packages with issues

---------

Co-authored-by: Olasunkanmi Oyinlola <olasunkanmioyinlola@Olasunkanmis-Mac-mini.local>

* display api error message

* display api error message

* save the ordersummary of each order, to recreate the order in order history

---------

Co-authored-by: Olasunkanmi Oyinlola <olasunkanmioyinlola@Olasunkanmis-Mac-mini.local>
  • Loading branch information
olasunkanmi-SE and Olasunkanmi Oyinlola committed Jan 20, 2024
1 parent 0657f9e commit 7166a26
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export interface IOrderDataModel {
readonly orderManagerId?: Types.ObjectId;
readonly cartItems?: CartItemDataModel[];
readonly orderStatusId: Types.ObjectId;
readonly summary: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export class OrderDataModel extends BaseDocument implements IOrderDataModel {
@Prop({ type: String, required: true })
type: dinningType;

@Prop({ type: String, required: true })
summary: string;

@Prop({ type: mongoose.Schema.Types.ObjectId })
@Type(() => SingleClientDataModel)
singleclientId: Types.ObjectId;
Expand Down
4 changes: 4 additions & 0 deletions backend/src/order/dto/create-order.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export class CreateOrderDTO {
@IsNotEmpty()
total: number;

@IsString()
@IsNotEmpty()
summary: string;

@IsOptional()
@IsArray()
cartItems: CreateCartItemsDTO[];
Expand Down
1 change: 1 addition & 0 deletions backend/src/order/order-entity.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface IOrder {
orderManagerId?: Types.ObjectId;
audit: Audit;
cartItems?: CartItem[];
summary: string;
}

//tableNumber
Expand Down
2 changes: 2 additions & 0 deletions backend/src/order/order-mock-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const orderMockData: IOrder = {
total: 1,
audit: Audit.create(auditMockData).getValue(),
cartItems: [cartItemMock],
summary: '',
};

export const orderMock: CreateOrderDTO = {
Expand All @@ -26,4 +27,5 @@ export const orderMock: CreateOrderDTO = {
singleClientId: id.toString(),
total: 1,
cartItems: [createItem],
summary: '',
};
20 changes: 17 additions & 3 deletions backend/src/order/order.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,19 @@ export class OrderMapper implements IMapper<Order, OrderDataModel> {
private readonly orderStatusMapper: OrderStatusMapper,
) {}
toPersistence(entity: Order): OrderDataModel {
const { id, state, type, singleclientId, total, discount, orderManagerId, audit, cartItems, orderStatusId } =
entity;
const {
id,
state,
type,
singleclientId,
total,
discount,
orderManagerId,
audit,
cartItems,
orderStatusId,
summary,
} = entity;
const {
auditCreatedBy,
auditCreatedDateTime,
Expand All @@ -34,6 +45,7 @@ export class OrderMapper implements IMapper<Order, OrderDataModel> {
discount,
cartItems: cartItems?.length ? cartItems.map((cartItem) => this.cartItemMapper.toPersistence(cartItem)) : [],
orderManagerId,
summary,
auditCreatedBy,
auditCreatedDateTime,
auditModifiedBy,
Expand All @@ -45,7 +57,8 @@ export class OrderMapper implements IMapper<Order, OrderDataModel> {
}

toDomain(model: OrderDataModel): Order {
const { state, type, singleclientId, total, discount, orderManagerId, _id, cartItems, orderStatusId } = model;
const { state, type, singleclientId, total, discount, orderManagerId, _id, cartItems, orderStatusId, summary } =
model;
const entity: Order = Order.create(
{
state: state ? this.orderStatusMapper.toDomain(state) : undefined,
Expand All @@ -55,6 +68,7 @@ export class OrderMapper implements IMapper<Order, OrderDataModel> {
total,
discount,
orderManagerId,
summary,
audit: this.auditMapper.toDomain(model),
cartItems: cartItems?.length ? cartItems.map((cartItem) => this.cartItemMapper.toDomain(cartItem)) : [],
},
Expand Down
3 changes: 2 additions & 1 deletion backend/src/order/order.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class OrderService implements IOrderService {

async createOrder(orderSummary: CreateOrderDTO): Promise<Result<IOrderResponseDTO>> {
await this.singleclientService.validateContext();
const { state, type, singleClientId, total, cartItems } = orderSummary;
const { state, type, singleClientId, total, cartItems, summary } = orderSummary;
const orderDuplicate = await this.orderRepository.getDuplicateOrder(type, singleClientId, cartItems);
if (orderDuplicate) {
throwApplicationError(HttpStatus.NOT_FOUND, 'Duplicate order detected. Please confirm.');
Expand All @@ -74,6 +74,7 @@ export class OrderService implements IOrderService {
type,
total,
singleclientId: singleclientObjId,
summary,
audit,
});
const orderModel: OrderDataModel = this.orderMapper.toPersistence(order);
Expand Down
7 changes: 7 additions & 0 deletions backend/src/order/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class Order extends Entity<IOrder> implements IOrder {
_orderManagerId: Types.ObjectId;
_audit: Audit;
_cartItems: CartItem[] | undefined;
_summary: string;

constructor(
id: Types.ObjectId,
Expand All @@ -30,6 +31,7 @@ export class Order extends Entity<IOrder> implements IOrder {
audit,
cartItems,
orderStatusId,
summary,
}: IOrder,
) {
super(id);
Expand All @@ -43,6 +45,7 @@ export class Order extends Entity<IOrder> implements IOrder {
this._audit = audit;
this._cartItems = cartItems;
this._orderStatusId = orderStatusId;
this._summary = summary;
}

get state(): OrderStatus {
Expand All @@ -53,6 +56,10 @@ export class Order extends Entity<IOrder> implements IOrder {
this._state = state;
}

get summary(): string {
return this._summary;
}

get type(): dinningType {
return this._type;
}
Expand Down
1 change: 1 addition & 0 deletions frontend/src/apis/orderApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const OrderApi = () => {
singleClientId: "63d78441a6fda119c09b1930",
total: calculateOrderTotalPrice(orderSummary) + serviceCharge,
cartItems: cartItemsMapper(orderSummary),
summary: JSON.stringify(orderSummary),
};
}
return order;
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/contexts/shoppingCartContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,12 @@ export const ShoppingCartProvider = ({ children }: shoppingCartProviderProps) =>
};

const addMenuToCart = (menu: IMenuData, instructions?: string) => {
//State.totalPrice is not correct
if (!state.menus.length) {
state.menus = menuToMenuStateMapper(menu);
state.quantity = 1;
}
let { menus, quantity, orderSummary } = state;
let { menus, quantity, orderSummary, totalPrice } = state;
if (instructions?.length) {
menus[0].note = instructions;
}
Expand Down
1 change: 1 addition & 0 deletions frontend/src/dto/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export interface ICreateOrderDTO {
singleClientId: string;
total: number;
cartItems: IcartItems[];
summary: string;
}

0 comments on commit 7166a26

Please sign in to comment.