Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development #397

Merged
merged 21 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}