Skip to content

Commit

Permalink
Development (#397)
Browse files Browse the repository at this point in the history
* implement the menu search

* fix code smell

* calculate service charge

* update sonar project config

* update total order calculation

* add cart items to order

* move email header check to the backend

* remove quantity from order

* update selected items to include itemId

* make cartitem and selectedCart Items optional in parent models

* create the order service

* create order controller

* checkout and fix (#391)

* Test (#393)

* checkout and fix

* fix errors and remove env from application (#392)

Co-authored-by: Olasunkanmi Oyinlola

* Offshore dev (#394)

* fix errors and remove env from application

* fix build errors

Co-authored-by: Olasunkanmi Oyinlola <143487325+olasunkanmiraymond@users.noreply.github.com>
Co-authored-by: Olasunkanmi Oyinlola <olasunkanmioyinlola@Olasunkanmis-MacBook-Air.local>

* Test (#396)

* checkout and fix

* fix errors and remove env from application (#392)

Co-authored-by: Olasunkanmi Oyinlola

* Offshore dev (#394)

* fix errors and remove env from application

* fix build errors

---------

Co-authored-by: Olasunkanmi Oyinlola <olasunkanmioyinlola@Olasunkanmis-MacBook-Air.local>

* Offshore dev (#395)

* fix errors and remove env from application

* fix build errors

* remove .env file from backend

---------

Co-authored-by: Olasunkanmi Oyinlola

---------

Co-authored-by: Olasunkanmi Oyinlola <143487325+olasunkanmiraymond@users.noreply.github.com>
Co-authored-by: Olasunkanmi Oyinlola <olasunkanmioyinlola@Olasunkanmis-MacBook-Air.local>

---------

Co-authored-by: Olasunkanmi Oyinlola <143487325+olasunkanmiraymond@users.noreply.github.com>
Co-authored-by: Olasunkanmi Oyinlola <olasunkanmioyinlola@Olasunkanmis-MacBook-Air.local>
  • Loading branch information
3 people authored Oct 24, 2023
1 parent 03c3e22 commit e297ace
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 16 deletions.
8 changes: 0 additions & 8 deletions backend/.env

This file was deleted.

5 changes: 4 additions & 1 deletion backend/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.env
# compiled output
/dist
/node_modules
Expand Down Expand Up @@ -33,4 +34,6 @@ lerna-debug.log*
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.vscode/launch.json
.vscode/launch.json

.env
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Injectable } from '@nestjs/common';
import { InjectConnection, InjectModel } from '@nestjs/mongoose';
import { Connection, Model, Types } from 'mongoose';
import { Connection, Model } from 'mongoose';
import { GenericDocumentRepository } from 'src/infrastructure/database';
import { Order } from 'src/order/order';
import { OrderMapper } from './../../../order/order.mapper';
import { OrderDataModel, OrderDocument } from './schemas/order.schema';
import { IOrderRepository } from './interfaces/order-repository.interface';
import { OrderDataModel, OrderDocument } from './schemas/order.schema';

@Injectable()
export class OrderRepository extends GenericDocumentRepository<Order, OrderDocument> implements IOrderRepository {
Expand Down
8 changes: 4 additions & 4 deletions backend/src/infrastructure/middlewares/context.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export class ContextMiddleWare implements NestMiddleware {
use(req: Request, res: Response, next: NextFunction) {
const headers = req.headers;
const errors = new Object() as any;
if (!Object.hasOwn(headers, APIResponseMessage.emailHeader)) {
errors.email = APIResponseMessage.emailHeaderError;
}
if (!Object.hasOwn(headers, APIResponseMessage.correlationIdHeader)) {
// if (!Object.hasOwn(headers, APIResponseMessage.emailHeader)) {
// errors.email = APIResponseMessage.emailHeaderError;
// }
if (!Object.hasOwnProperty.call(headers, APIResponseMessage.correlationIdHeader)) {
errors.correlationId = APIResponseMessage.correlationIdHeaderError;
}
for (const [key, value] of Object.entries(headers)) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/apis/menusApi.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IMenu, IMenus } from "../models/menu.model";
import { IMenu } from "../models/menu.model";
import { ICreateMenu } from "../interfaces/menu.interface";
import { QueryObserverResult, useQuery } from "react-query";
import { menuApi } from "./axios";
Expand Down
49 changes: 49 additions & 0 deletions frontend/src/apis/orderApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { SelectedItem } from "./../reducers/cartReducer";
import { useShoppingCart } from "../hooks/UseShoppingCart";

export const createOrder = async (order: any) => {};

const getOrderSummary = () => {
const { GetOrderSummary } = useShoppingCart();
return GetOrderSummary();
};

const reduceSelectedItems = () => {
const orderSummary = getOrderSummary();
let selectedItems: SelectedItem[] = [];
if (orderSummary?.length) {
selectedItems = orderSummary.reduce((result: SelectedItem[], item) => {
if (item.menus?.length) {
item.menus.forEach((menu) => {
if (menu.selectedItems) {
menu.selectedItems.forEach((selectedItem) => {
const itemId = selectedItem.id;
const existingItem = result.find(
(item: any) => item.id === itemId
);
if (existingItem) {
existingItem.price += selectedItem.price;
existingItem.quantity! += selectedItem.quantity!;
} else {
result.push({ ...selectedItem });
}
});
}
});
}
return result;
}, []);
}
return selectedItems;
};

// const getCartItems = () => {
// const orderSummary = getOrderSummary();
// if (orderSummary?.length) {
// const selectedItemsMap = new Map<string, SelectedItem>();
// reduceSelectedItems.forEach((item) => {});
// orderSummary.map((summary) => {
// const cartItem = summary.menus;
// });
// }
// };
1 change: 1 addition & 0 deletions frontend/src/contexts/shoppingCartContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ export const ShoppingCartProvider = ({ children }: shoppingCartProviderProps) =>

const updateCartItems = (orderSummary: OrderSummary[]) => {
state.orderSummary = orderSummary;
console.log(state.orderSummary);
setLocalStorageData("cart", JSON.stringify(state), true);
dispatch({
type: CartActionsType.UPDATE_CART_ITEMS,
Expand Down
21 changes: 21 additions & 0 deletions frontend/src/models/order.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export interface IOrder {
state: string;
type: string;
merchantId: string;
total: number;
cartItems: IcartItems[];
}

export interface IcartItems {
menuId: string;
total: number;
quantity: number;
selectedItems: IselectedItems[];
}

export interface IselectedItems {
itemId: string;
menuId: string;
price: number;
quantity: number;
}

0 comments on commit e297ace

Please sign in to comment.