Skip to content

Commit

Permalink
349 place order (#478)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
olasunkanmi-SE and Olasunkanmi Oyinlola authored Jan 20, 2024
1 parent 2a322c1 commit c76fa9f
Show file tree
Hide file tree
Showing 6 changed files with 818 additions and 320 deletions.
2 changes: 1 addition & 1 deletion backend/src/order/order.parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class OrderParser {
total,
discount,
orderManagerId,
notes: OrderNoteParser.createOrderNotesResponse(notes) || [],
notes: notes ? OrderNoteParser.createOrderNotesResponse(notes) : [],
...AuditParser.createAuditResponse(audit),
};
}
Expand Down
22 changes: 12 additions & 10 deletions backend/src/order/order.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,12 @@ export class OrderService implements IOrderService {
const insertedItems: Result<SelectedCartItem[]> = await this.selectedCartItemRepository.insertMany(
selectedCartItemsDataModel,
);
const notes = await this.createOrderNotes(cartItems, orderId);
if (!insertedItems.isSuccess) {
throwApplicationError(HttpStatus.INTERNAL_SERVER_ERROR, `Could not create an order`);
}
const response: IOrderResponseDTO | undefined = OrderParser.createOrderResponse(savedOrder, notes);
const notes = await this.createOrderNotes(cartItems, orderId);
const notesToSave: OrderNote[] = notes || [];
const response: IOrderResponseDTO | undefined = OrderParser.createOrderResponse(savedOrder, notesToSave);
const savedSelectedItems = insertedItems.getValue();
const savedItemsMap = savedSelectedItems.reduce((map, item) => {
const cartItemIdToString = this.cartItemRepository.objectIdToString(item.cartItemId);
Expand Down Expand Up @@ -161,20 +162,21 @@ export class OrderService implements IOrderService {
}

async createOrderNotes(cartItems: CreateCartItemsDTO[], orderId: Types.ObjectId): Promise<OrderNote[]> {
const orderNotes = cartItems.map(({ menuId, note }: CreateCartItemsDTO) => {
let noteToSave: { menuId: Types.ObjectId; note: string; orderId: Types.ObjectId } | undefined;
const orderNotes: { menuId: Types.ObjectId; note: string; orderId: Types.ObjectId }[] = [];
cartItems.forEach(({ menuId, note }: CreateCartItemsDTO) => {
if (note?.length) {
noteToSave = {
orderNotes.push({
menuId,
note: note,
orderId: orderId,
};
});
}
return noteToSave;
});
const notesToSave = orderNotes.filter((note) => note !== undefined);
const notes = await this.orderNoteService.createNotes(notesToSave);
return notes.getValue();

if (orderNotes.length) {
const notes = await this.orderNoteService.createNotes(orderNotes);
return notes.getValue();
}
}

async createOrderStatusQueue(orderStatusId: Types.ObjectId, orderId: Types.ObjectId) {
Expand Down
Loading

0 comments on commit c76fa9f

Please sign in to comment.