From 848a3528d287b8fadd4618d34b29c68ea870de4d Mon Sep 17 00:00:00 2001 From: amywng <147568742+amywng@users.noreply.github.com> Date: Sun, 8 Feb 2026 20:07:55 -0500 Subject: [PATCH 1/9] add orders tests --- .../src/orders/order.controller.spec.ts | 149 +++++++++ apps/backend/src/orders/order.service.spec.ts | 297 ++++++++++++++++++ apps/backend/src/orders/order.service.ts | 4 - 3 files changed, 446 insertions(+), 4 deletions(-) diff --git a/apps/backend/src/orders/order.controller.spec.ts b/apps/backend/src/orders/order.controller.spec.ts index 980fc6ba..3ecd7b1c 100644 --- a/apps/backend/src/orders/order.controller.spec.ts +++ b/apps/backend/src/orders/order.controller.spec.ts @@ -9,6 +9,8 @@ import { OrderStatus } from './types'; import { FoodRequest } from '../foodRequests/request.entity'; import { Pantry } from '../pantries/pantries.entity'; import { TrackingCostDto } from './dtos/tracking-cost.dto'; +import { BadRequestException } from '@nestjs/common'; +import { FoodManufacturer } from '../foodManufacturers/manufacturer.entity'; const mockOrdersService = mock(); const mockAllocationsService = mock(); @@ -28,21 +30,29 @@ describe('OrdersController', () => { { requestId: 3, pantry: mockPantries[2] as Pantry }, ]; + const mockFoodManufacturer: Partial = { + foodManufacturerId: 1, + foodManufacturerName: 'Test FM', + }; + const mockOrders: Partial[] = [ { orderId: 1, status: OrderStatus.PENDING, request: mockRequests[0] as FoodRequest, + foodManufacturer: mockFoodManufacturer as FoodManufacturer, }, { orderId: 2, status: OrderStatus.DELIVERED, request: mockRequests[1] as FoodRequest, + foodManufacturer: mockFoodManufacturer as FoodManufacturer, }, { orderId: 3, status: OrderStatus.SHIPPED, request: mockRequests[2] as FoodRequest, + foodManufacturer: mockFoodManufacturer as FoodManufacturer, }, ]; @@ -86,6 +96,122 @@ describe('OrdersController', () => { }); }); + describe('getCurrentOrders', () => { + it('should call ordersService.getCurrentOrders and return orders', async () => { + mockOrdersService.getCurrentOrders.mockResolvedValueOnce([ + mockOrders[0], + mockOrders[2], + ] as Order[]); + + const result = await controller.getCurrentOrders(); + + expect(result).toEqual([mockOrders[0], mockOrders[2]] as Order[]); + expect(mockOrdersService.getCurrentOrders).toHaveBeenCalled(); + }); + }); + + describe('getPastOrders', () => { + it('should call ordersService.getPastOrders and return orders', async () => { + mockOrdersService.getPastOrders.mockResolvedValueOnce([ + mockOrders[1], + ] as Order[]); + + const result = await controller.getPastOrders(); + + expect(result).toEqual([mockOrders[1]] as Order[]); + expect(mockOrdersService.getPastOrders).toHaveBeenCalled(); + }); + }); + + describe('getPantryFromOrder', () => { + it('should call ordersService.findOrderPantry and return pantry', async () => { + const orderId = 1; + mockOrdersService.findOrderPantry.mockResolvedValueOnce( + mockPantries[0] as Pantry, + ); + + const result = await controller.getPantryFromOrder(orderId); + + expect(result).toEqual(mockPantries[0] as Pantry); + expect(mockOrdersService.findOrderPantry).toHaveBeenCalledWith(orderId); + }); + + it('should throw for non-numeric input', async () => { + const invalidInput = NaN; + mockOrdersService.findOrderPantry.mockRejectedValue( + new BadRequestException( + 'Validation failed (numeric string is expected)', + ), + ); + + await expect(controller.getPantryFromOrder(invalidInput)).rejects.toThrow( + new BadRequestException( + 'Validation failed (numeric string is expected)', + ), + ); + }); + }); + + describe('getRequestFromOrder', () => { + it('should call ordersService.findOrderFoodRequest and return food request', async () => { + const orderId = 1; + mockOrdersService.findOrderFoodRequest.mockResolvedValueOnce( + mockRequests[0] as FoodRequest, + ); + + const result = await controller.getRequestFromOrder(orderId); + + expect(result).toEqual(mockRequests[0] as Pantry); + expect(mockOrdersService.findOrderFoodRequest).toHaveBeenCalledWith( + orderId, + ); + }); + }); + + describe('getManufacturerFromOrder', () => { + it('should call ordersService.findOrderFoodManufacturer and return FM', async () => { + const orderId = 1; + mockOrdersService.findOrderFoodManufacturer.mockResolvedValueOnce( + mockFoodManufacturer as FoodManufacturer, + ); + + const result = await controller.getManufacturerFromOrder(orderId); + + expect(result).toEqual(mockFoodManufacturer as FoodManufacturer); + expect(mockOrdersService.findOrderFoodManufacturer).toHaveBeenCalledWith( + orderId, + ); + }); + }); + + describe('getOrder', () => { + it('should call ordersService.findOne and return order', async () => { + const orderId = 1; + mockOrdersService.findOne.mockResolvedValueOnce(mockOrders[0] as Order); + + const result = await controller.getOrder(orderId); + + expect(result).toEqual(mockOrders[0] as Order); + expect(mockOrdersService.findOne).toHaveBeenCalledWith(orderId); + }); + }); + + describe('getOrderByRequestId', () => { + it('should call ordersService.findOrderByRequest and return order', async () => { + const requestId = 1; + mockOrdersService.findOrderByRequest.mockResolvedValueOnce( + mockOrders[0] as Order, + ); + + const result = await controller.getOrderByRequestId(requestId); + + expect(result).toEqual(mockOrders[0] as Order); + expect(mockOrdersService.findOrderByRequest).toHaveBeenCalledWith( + requestId, + ); + }); + }); + describe('getAllAllocationsByOrder', () => { it('should call allocationsService.getAllAllocationsByOrder and return allocations', async () => { const orderId = 1; @@ -102,6 +228,29 @@ describe('OrdersController', () => { }); }); + describe('updateStatus', () => { + it('should call ordersService.updateStatus', async () => { + const status = OrderStatus.DELIVERED; + const orderId = 1; + + await controller.updateStatus(orderId, status); + + expect(mockOrdersService.updateStatus).toHaveBeenCalledWith( + orderId, + status, + ); + }); + + it('should throw with invalid status', async () => { + const invalidStatus = 'invalid status'; + const orderId = 1; + + await expect( + controller.updateStatus(orderId, invalidStatus), + ).rejects.toThrow(new BadRequestException('Invalid status')); + }); + }); + describe('updateTrackingCostInfo', () => { it('should call ordersService.updateTrackingCostInfo with correct parameters', async () => { const orderId = 1; diff --git a/apps/backend/src/orders/order.service.spec.ts b/apps/backend/src/orders/order.service.spec.ts index e8e41949..bbf8281b 100644 --- a/apps/backend/src/orders/order.service.spec.ts +++ b/apps/backend/src/orders/order.service.spec.ts @@ -5,6 +5,8 @@ import { Order } from './order.entity'; import { testDataSource } from '../config/typeormTestDataSource'; import { OrderStatus } from './types'; import { Pantry } from '../pantries/pantries.entity'; +import { BadRequestException, NotFoundException } from '@nestjs/common'; +import { TrackingCostDto } from './dtos/tracking-cost.dto'; // Set 1 minute timeout for async DB operations jest.setTimeout(60000); @@ -121,4 +123,299 @@ describe('OrdersService', () => { expect(orders[0].status).toBe(OrderStatus.DELIVERED); }); }); + + describe('getCurrentOrders', () => { + it(`returns only orders with status 'pending' or 'shipped'`, async () => { + const orders = await service.getCurrentOrders(); + expect(orders).toHaveLength(2); + expect( + orders.every( + (order) => + order.status === OrderStatus.PENDING || + order.status === OrderStatus.SHIPPED, + ), + ).toBe(true); + }); + }); + + describe('getPastOrders', () => { + it(`returns only orders with status 'delivered'`, async () => { + const orders = await service.getPastOrders(); + expect(orders).toHaveLength(2); + expect( + orders.every((order) => order.status === OrderStatus.DELIVERED), + ).toBe(true); + }); + }); + + describe('findOne', () => { + it('returns order by ID', async () => { + const orderId = 1; + const result = await service.findOne(orderId); + + expect(result).toBeDefined(); + expect(result.orderId).toBe(1); + }); + + it('throws BadRequestException for non positive ID', async () => { + const orderId = 0; + await expect(service.findOne(orderId)).rejects.toThrow( + new BadRequestException('Invalid Order ID'), + ); + }); + + it('throws BadRequestException when not given ID', async () => { + await expect(service.findOne(null)).rejects.toThrow( + new BadRequestException('Invalid Order ID'), + ); + }); + + it('throws NotFoundException for non-existent order', async () => { + await expect(service.findOne(9999)).rejects.toThrow( + new NotFoundException('Order 9999 not found'), + ); + }); + }); + + describe('findOrderByRequest', () => { + it('returns order by request ID', async () => { + const order = await service.findOrderByRequest(1); + + expect(order).toBeDefined(); + expect(order.requestId).toBe(1); + }); + + it('validates ID', async () => { + await expect(service.findOrderByRequest(0)).rejects.toThrow( + new BadRequestException('Invalid Request ID'), + ); + await expect(service.findOrderByRequest(null)).rejects.toThrow( + new BadRequestException('Invalid Request ID'), + ); + }); + + it('throws NotFoundException for non-existent order', async () => { + await expect(service.findOrderByRequest(9999)).rejects.toThrow( + new NotFoundException('Order with request ID 9999 not found'), + ); + }); + }); + + describe('findOrderFoodRequest', () => { + it('returns food request of order', async () => { + const foodRequest = await service.findOrderFoodRequest(1); + + expect(foodRequest).toBeDefined(); + expect(foodRequest.requestId).toBe(1); + }); + + it('validates order ID', async () => { + await expect(service.findOrderFoodRequest(0)).rejects.toThrow( + new BadRequestException('Invalid Order ID'), + ); + await expect(service.findOrderFoodRequest(null)).rejects.toThrow( + new BadRequestException('Invalid Order ID'), + ); + }); + + it('throws NotFoundException for non-existent order', async () => { + await expect(service.findOrderFoodRequest(9999)).rejects.toThrow( + new NotFoundException('Order 9999 not found'), + ); + }); + }); + + describe('findOrderPantry', () => { + it('returns pantry of order', async () => { + const pantry = await service.findOrderPantry(1); + + expect(pantry).toBeDefined(); + expect(pantry.pantryName).toEqual('Community Food Pantry Downtown'); + expect(pantry.pantryId).toEqual(1); + }); + }); + + describe('findOrderFoodManufacturer', () => { + it('returns FM of order', async () => { + const foodManufacturer = await service.findOrderFoodManufacturer(2); + + expect(foodManufacturer).toBeDefined(); + expect(foodManufacturer.foodManufacturerName).toEqual('Healthy Foods Co'); + expect(foodManufacturer.foodManufacturerId).toEqual(2); + }); + + it('validates order ID', async () => { + await expect(service.findOrderFoodManufacturer(0)).rejects.toThrow( + new BadRequestException('Invalid Order ID'), + ); + await expect(service.findOrderFoodManufacturer(null)).rejects.toThrow( + new BadRequestException('Invalid Order ID'), + ); + }); + + it('throws NotFoundException for non-existent order', async () => { + await expect(service.findOrderFoodManufacturer(9999)).rejects.toThrow( + new NotFoundException('Order 9999 not found'), + ); + }); + }); + + describe('updateStatus', () => { + it('updates order status to delivered', async () => { + const orderId = 3; + const order = await service.findOne(orderId); + + expect(order.status).toEqual(OrderStatus.SHIPPED); + + await service.updateStatus(orderId, OrderStatus.DELIVERED); + const updatedOrder = await service.findOne(orderId); + + expect(updatedOrder.status).toEqual(OrderStatus.DELIVERED); + expect(updatedOrder.deliveredAt).toBeDefined(); + }); + + it('updates order status to shipped', async () => { + const orderId = 4; + const order = await service.findOne(orderId); + + expect(order.status).toEqual(OrderStatus.PENDING); + + await service.updateStatus(orderId, OrderStatus.SHIPPED); + const updatedOrder = await service.findOne(orderId); + + expect(updatedOrder.status).toEqual(OrderStatus.SHIPPED); + expect(updatedOrder.shippedAt).toBeDefined(); + expect(updatedOrder.deliveredAt).toBeNull(); + }); + + it('validates order ID', async () => { + await expect( + service.updateStatus(0, OrderStatus.DELIVERED), + ).rejects.toThrow(new BadRequestException('Invalid Order ID')); + await expect( + service.updateStatus(null, OrderStatus.DELIVERED), + ).rejects.toThrow(new BadRequestException('Invalid Order ID')); + }); + }); + + describe('getOrdersByPantry', () => { + it('validates pantry ID', async () => { + await expect(service.getOrdersByPantry(0)).rejects.toThrow( + new BadRequestException('Invalid Pantry ID'), + ); + await expect(service.getOrdersByPantry(null)).rejects.toThrow( + new BadRequestException('Invalid Pantry ID'), + ); + }); + + it('returns order from pantry ID', async () => { + const pantryId = 1; + const orders = await service.getOrdersByPantry(pantryId); + + expect(orders.length).toBe(2); + expect(orders.every((order) => order.request.pantryId === 1)).toBe(true); + }); + + it('returns empty list for pantry with no orderes', async () => { + const pantryId = 5; + const orders = await service.getOrdersByPantry(pantryId); + + expect(orders).toEqual([]); + }); + }); + + describe('updateTrackingCostInfo', () => { + it('validates order ID', async () => { + await expect(service.updateTrackingCostInfo(0, {})).rejects.toThrow( + new BadRequestException('Invalid Order ID'), + ); + await expect(service.updateTrackingCostInfo(null, {})).rejects.toThrow( + new BadRequestException('Invalid Order ID'), + ); + }); + + it('throws when order is non-existent', async () => { + const trackingCostDto: TrackingCostDto = { + trackingLink: 'test', + shippingCost: 5.99, + }; + + await expect( + service.updateTrackingCostInfo(9999, trackingCostDto), + ).rejects.toThrow(new NotFoundException('Order 9999 not found')); + }); + + it('throws when tracking link and shipping cost not given', async () => { + await expect(service.updateTrackingCostInfo(3, {})).rejects.toThrow( + new BadRequestException( + 'At least one of tracking link or shipping cost must be provided', + ), + ); + }); + + it('updates tracking link for shipped order', async () => { + const trackingCostDto: TrackingCostDto = { + trackingLink: 'samplelink.com', + }; + + await service.updateTrackingCostInfo(3, trackingCostDto); + + const order = await service.findOne(3); + expect(order.trackingLink).toBeDefined(); + expect(order.trackingLink).toEqual('samplelink.com'); + }); + + it('updates shipping cost for shipped order', async () => { + const trackingCostDto: TrackingCostDto = { + shippingCost: 12.99, + }; + + await service.updateTrackingCostInfo(3, trackingCostDto); + + const order = await service.findOne(3); + expect(order.shippingCost).toBeDefined(); + expect(order.shippingCost).toEqual('12.99'); + }); + + it('updates both shipping cost and tracking link', async () => { + const trackingCostDto: TrackingCostDto = { + trackingLink: 'testtracking.com', + shippingCost: 7.5, + }; + + await service.updateTrackingCostInfo(3, trackingCostDto); + + const order = await service.findOne(3); + expect(order.trackingLink).toEqual('testtracking.com'); + expect(order.shippingCost).toEqual('7.50'); + }); + }); + + it('throws BadRequestException for non-shipped order', async () => { + const trackingCostDto: TrackingCostDto = { + trackingLink: 'testtracking.com', + shippingCost: 7.5, + }; + + const order1 = await service.findOne(2); + const order2 = await service.findOne(4); + + expect(order1.status).toEqual(OrderStatus.DELIVERED); + expect(order2.status).toEqual(OrderStatus.PENDING); + + await expect( + service.updateTrackingCostInfo(2, trackingCostDto), + ).rejects.toThrow( + new BadRequestException( + 'Can only update tracking info for shipped orders', + ), + ); + await expect( + service.updateTrackingCostInfo(4, trackingCostDto), + ).rejects.toThrow( + new BadRequestException( + 'Can only update tracking info for shipped orders', + ), + ); + }); }); diff --git a/apps/backend/src/orders/order.service.ts b/apps/backend/src/orders/order.service.ts index 4948f2fd..0746d83a 100644 --- a/apps/backend/src/orders/order.service.ts +++ b/apps/backend/src/orders/order.service.ts @@ -97,10 +97,6 @@ export class OrdersService { pantryId: request.pantryId, }); - if (!pantry) { - throw new NotFoundException(`Pantry ${request.pantryId} not found`); - } - return pantry; } From e8b48e885bd428b7ba04932b58c606013353c685 Mon Sep 17 00:00:00 2001 From: amywng <147568742+amywng@users.noreply.github.com> Date: Sun, 8 Feb 2026 20:12:16 -0500 Subject: [PATCH 2/9] move test inside describe --- apps/backend/src/orders/order.service.spec.ts | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/apps/backend/src/orders/order.service.spec.ts b/apps/backend/src/orders/order.service.spec.ts index bbf8281b..94ccfa2c 100644 --- a/apps/backend/src/orders/order.service.spec.ts +++ b/apps/backend/src/orders/order.service.spec.ts @@ -389,33 +389,33 @@ describe('OrdersService', () => { expect(order.trackingLink).toEqual('testtracking.com'); expect(order.shippingCost).toEqual('7.50'); }); - }); - it('throws BadRequestException for non-shipped order', async () => { - const trackingCostDto: TrackingCostDto = { - trackingLink: 'testtracking.com', - shippingCost: 7.5, - }; - - const order1 = await service.findOne(2); - const order2 = await service.findOne(4); - - expect(order1.status).toEqual(OrderStatus.DELIVERED); - expect(order2.status).toEqual(OrderStatus.PENDING); - - await expect( - service.updateTrackingCostInfo(2, trackingCostDto), - ).rejects.toThrow( - new BadRequestException( - 'Can only update tracking info for shipped orders', - ), - ); - await expect( - service.updateTrackingCostInfo(4, trackingCostDto), - ).rejects.toThrow( - new BadRequestException( - 'Can only update tracking info for shipped orders', - ), - ); + it('throws BadRequestException for non-shipped order', async () => { + const trackingCostDto: TrackingCostDto = { + trackingLink: 'testtracking.com', + shippingCost: 7.5, + }; + + const order1 = await service.findOne(2); + const order2 = await service.findOne(4); + + expect(order1.status).toEqual(OrderStatus.DELIVERED); + expect(order2.status).toEqual(OrderStatus.PENDING); + + await expect( + service.updateTrackingCostInfo(2, trackingCostDto), + ).rejects.toThrow( + new BadRequestException( + 'Can only update tracking info for shipped orders', + ), + ); + await expect( + service.updateTrackingCostInfo(4, trackingCostDto), + ).rejects.toThrow( + new BadRequestException( + 'Can only update tracking info for shipped orders', + ), + ); + }); }); }); From e49b51cc79c40081462b9d3169526c7438a65374 Mon Sep 17 00:00:00 2001 From: amywng <147568742+amywng@users.noreply.github.com> Date: Tue, 10 Feb 2026 15:46:39 -0500 Subject: [PATCH 3/9] add test for fixed logic --- apps/backend/src/orders/order.service.spec.ts | 61 ++++++++++++++++--- 1 file changed, 53 insertions(+), 8 deletions(-) diff --git a/apps/backend/src/orders/order.service.spec.ts b/apps/backend/src/orders/order.service.spec.ts index 94ccfa2c..033cf13e 100644 --- a/apps/backend/src/orders/order.service.spec.ts +++ b/apps/backend/src/orders/order.service.spec.ts @@ -390,32 +390,77 @@ describe('OrdersService', () => { expect(order.shippingCost).toEqual('7.50'); }); - it('throws BadRequestException for non-shipped order', async () => { + it('throws BadRequestException for delivered order', async () => { const trackingCostDto: TrackingCostDto = { trackingLink: 'testtracking.com', shippingCost: 7.5, }; + const orderId = 2; - const order1 = await service.findOne(2); - const order2 = await service.findOne(4); + const order = await service.findOne(orderId); - expect(order1.status).toEqual(OrderStatus.DELIVERED); - expect(order2.status).toEqual(OrderStatus.PENDING); + expect(order.status).toEqual(OrderStatus.DELIVERED); await expect( - service.updateTrackingCostInfo(2, trackingCostDto), + service.updateTrackingCostInfo(orderId, trackingCostDto), ).rejects.toThrow( new BadRequestException( - 'Can only update tracking info for shipped orders', + 'Can only update tracking info for pending or shipped orders', ), ); + }); + + it('throws when both fields are not provided for first time setting', async () => { + const trackingCostDto: TrackingCostDto = { + trackingLink: 'testtracking.com', + }; + const orderId = 4; + + const order = await service.findOne(orderId); + + expect(order.shippedAt).toBeNull(); + expect(order.trackingLink).toBeNull(); + await expect( service.updateTrackingCostInfo(4, trackingCostDto), ).rejects.toThrow( new BadRequestException( - 'Can only update tracking info for shipped orders', + 'Must provide both tracking link and shipping cost on initial assignment', ), ); }); + + it('sets status to shipped when both fields provided and previous status pending', async () => { + const trackingCostDto: TrackingCostDto = { + trackingLink: 'testtracking.com', + shippingCost: 5.75, + }; + const orderId = 4; + + const order = await service.findOne(orderId); + console.log('BEFORE UPDATE:', { + orderId: order.orderId, + status: order.status, + trackingLink: order.trackingLink, + shippingCost: order.shippingCost, + shippedAt: order.shippedAt, + }); + + expect(order.status).toEqual(OrderStatus.PENDING); + expect(order.shippedAt).toBeNull(); + + await service.updateTrackingCostInfo(orderId, trackingCostDto); + + const updatedOrder = await service.findOne(orderId); + console.log('AFTER UPDATE:', { + orderId: updatedOrder.orderId, + status: updatedOrder.status, + trackingLink: updatedOrder.trackingLink, + shippingCost: updatedOrder.shippingCost, + shippedAt: updatedOrder.shippedAt, + }); + expect(updatedOrder.status).toEqual(OrderStatus.SHIPPED); + expect(updatedOrder.shippedAt).toBeDefined(); + }); }); }); From e6388c43a3362cf26722d376137bd6aba09b7992 Mon Sep 17 00:00:00 2001 From: amywng <147568742+amywng@users.noreply.github.com> Date: Tue, 10 Feb 2026 15:50:40 -0500 Subject: [PATCH 4/9] remove validate id tests --- apps/backend/src/orders/order.service.spec.ts | 54 ------------------- 1 file changed, 54 deletions(-) diff --git a/apps/backend/src/orders/order.service.spec.ts b/apps/backend/src/orders/order.service.spec.ts index 033cf13e..e554f11b 100644 --- a/apps/backend/src/orders/order.service.spec.ts +++ b/apps/backend/src/orders/order.service.spec.ts @@ -185,15 +185,6 @@ describe('OrdersService', () => { expect(order.requestId).toBe(1); }); - it('validates ID', async () => { - await expect(service.findOrderByRequest(0)).rejects.toThrow( - new BadRequestException('Invalid Request ID'), - ); - await expect(service.findOrderByRequest(null)).rejects.toThrow( - new BadRequestException('Invalid Request ID'), - ); - }); - it('throws NotFoundException for non-existent order', async () => { await expect(service.findOrderByRequest(9999)).rejects.toThrow( new NotFoundException('Order with request ID 9999 not found'), @@ -209,15 +200,6 @@ describe('OrdersService', () => { expect(foodRequest.requestId).toBe(1); }); - it('validates order ID', async () => { - await expect(service.findOrderFoodRequest(0)).rejects.toThrow( - new BadRequestException('Invalid Order ID'), - ); - await expect(service.findOrderFoodRequest(null)).rejects.toThrow( - new BadRequestException('Invalid Order ID'), - ); - }); - it('throws NotFoundException for non-existent order', async () => { await expect(service.findOrderFoodRequest(9999)).rejects.toThrow( new NotFoundException('Order 9999 not found'), @@ -244,15 +226,6 @@ describe('OrdersService', () => { expect(foodManufacturer.foodManufacturerId).toEqual(2); }); - it('validates order ID', async () => { - await expect(service.findOrderFoodManufacturer(0)).rejects.toThrow( - new BadRequestException('Invalid Order ID'), - ); - await expect(service.findOrderFoodManufacturer(null)).rejects.toThrow( - new BadRequestException('Invalid Order ID'), - ); - }); - it('throws NotFoundException for non-existent order', async () => { await expect(service.findOrderFoodManufacturer(9999)).rejects.toThrow( new NotFoundException('Order 9999 not found'), @@ -287,27 +260,9 @@ describe('OrdersService', () => { expect(updatedOrder.shippedAt).toBeDefined(); expect(updatedOrder.deliveredAt).toBeNull(); }); - - it('validates order ID', async () => { - await expect( - service.updateStatus(0, OrderStatus.DELIVERED), - ).rejects.toThrow(new BadRequestException('Invalid Order ID')); - await expect( - service.updateStatus(null, OrderStatus.DELIVERED), - ).rejects.toThrow(new BadRequestException('Invalid Order ID')); - }); }); describe('getOrdersByPantry', () => { - it('validates pantry ID', async () => { - await expect(service.getOrdersByPantry(0)).rejects.toThrow( - new BadRequestException('Invalid Pantry ID'), - ); - await expect(service.getOrdersByPantry(null)).rejects.toThrow( - new BadRequestException('Invalid Pantry ID'), - ); - }); - it('returns order from pantry ID', async () => { const pantryId = 1; const orders = await service.getOrdersByPantry(pantryId); @@ -325,15 +280,6 @@ describe('OrdersService', () => { }); describe('updateTrackingCostInfo', () => { - it('validates order ID', async () => { - await expect(service.updateTrackingCostInfo(0, {})).rejects.toThrow( - new BadRequestException('Invalid Order ID'), - ); - await expect(service.updateTrackingCostInfo(null, {})).rejects.toThrow( - new BadRequestException('Invalid Order ID'), - ); - }); - it('throws when order is non-existent', async () => { const trackingCostDto: TrackingCostDto = { trackingLink: 'test', From 917126ea960991c8d80b28b1cdcbff0c9a3c4e2e Mon Sep 17 00:00:00 2001 From: amywng <147568742+amywng@users.noreply.github.com> Date: Thu, 12 Feb 2026 06:43:55 -0500 Subject: [PATCH 5/9] review comments and fix shippedBy column --- .../1769990652833-UpdateOrderEntity.ts | 6 +++ .../src/orders/order.controller.spec.ts | 2 +- apps/backend/src/orders/order.service.spec.ts | 52 +++++++++---------- apps/backend/src/orders/order.service.ts | 4 ++ 4 files changed, 36 insertions(+), 28 deletions(-) diff --git a/apps/backend/src/migrations/1769990652833-UpdateOrderEntity.ts b/apps/backend/src/migrations/1769990652833-UpdateOrderEntity.ts index 780483df..6ebe4a74 100644 --- a/apps/backend/src/migrations/1769990652833-UpdateOrderEntity.ts +++ b/apps/backend/src/migrations/1769990652833-UpdateOrderEntity.ts @@ -11,6 +11,9 @@ export class UpdateOrderEntity1769990652833 implements MigrationInterface { SET tracking_link = 'www.samplelink/samplelink', shipping_cost = 20.00 WHERE status = 'delivered' OR status = 'shipped' AND shipped_at IS NOT NULL; + + ALTER TABLE orders + ALTER COLUMN shipped_by DROP NOT NULL; `); } @@ -19,6 +22,9 @@ export class UpdateOrderEntity1769990652833 implements MigrationInterface { ALTER TABLE orders DROP COLUMN IF EXISTS tracking_link, DROP COLUMN IF EXISTS shipping_cost; + + ALTER TABLE orders + ALTER COLUMN shipped_by SET NOT NULL; `); } } diff --git a/apps/backend/src/orders/order.controller.spec.ts b/apps/backend/src/orders/order.controller.spec.ts index 3ecd7b1c..baf91fde 100644 --- a/apps/backend/src/orders/order.controller.spec.ts +++ b/apps/backend/src/orders/order.controller.spec.ts @@ -10,7 +10,7 @@ import { FoodRequest } from '../foodRequests/request.entity'; import { Pantry } from '../pantries/pantries.entity'; import { TrackingCostDto } from './dtos/tracking-cost.dto'; import { BadRequestException } from '@nestjs/common'; -import { FoodManufacturer } from '../foodManufacturers/manufacturer.entity'; +import { FoodManufacturer } from '../foodManufacturers/manufacturers.entity'; const mockOrdersService = mock(); const mockAllocationsService = mock(); diff --git a/apps/backend/src/orders/order.service.spec.ts b/apps/backend/src/orders/order.service.spec.ts index e554f11b..e0e8f195 100644 --- a/apps/backend/src/orders/order.service.spec.ts +++ b/apps/backend/src/orders/order.service.spec.ts @@ -157,19 +157,6 @@ describe('OrdersService', () => { expect(result.orderId).toBe(1); }); - it('throws BadRequestException for non positive ID', async () => { - const orderId = 0; - await expect(service.findOne(orderId)).rejects.toThrow( - new BadRequestException('Invalid Order ID'), - ); - }); - - it('throws BadRequestException when not given ID', async () => { - await expect(service.findOne(null)).rejects.toThrow( - new BadRequestException('Invalid Order ID'), - ); - }); - it('throws NotFoundException for non-existent order', async () => { await expect(service.findOne(9999)).rejects.toThrow( new NotFoundException('Order 9999 not found'), @@ -182,6 +169,7 @@ describe('OrdersService', () => { const order = await service.findOrderByRequest(1); expect(order).toBeDefined(); + expect(order.request).toBeDefined(); expect(order.requestId).toBe(1); }); @@ -231,6 +219,18 @@ describe('OrdersService', () => { new NotFoundException('Order 9999 not found'), ); }); + + it('throws NotFoundException if order has no FM assigned', async () => { + await testDataSource.query( + `UPDATE "orders" SET shipped_by = NULL WHERE order_id = 4`, + ); + + await expect(service.findOrderFoodManufacturer(4)).rejects.toThrow( + new NotFoundException( + 'Order 4 does not have a food manufacturer assigned', + ), + ); + }); }); describe('updateStatus', () => { @@ -239,6 +239,8 @@ describe('OrdersService', () => { const order = await service.findOne(orderId); expect(order.status).toEqual(OrderStatus.SHIPPED); + expect(order.shippedBy).toBeDefined(); + expect(order.shippedAt).toBeDefined(); await service.updateStatus(orderId, OrderStatus.DELIVERED); const updatedOrder = await service.findOne(orderId); @@ -268,6 +270,7 @@ describe('OrdersService', () => { const orders = await service.getOrdersByPantry(pantryId); expect(orders.length).toBe(2); + expect(orders.every((order) => order.request)).toBeDefined(); expect(orders.every((order) => order.request.pantryId === 1)).toBe(true); }); @@ -277,6 +280,14 @@ describe('OrdersService', () => { expect(orders).toEqual([]); }); + + it('throws NotFoundException for non-existent pantry', async () => { + const pantryId = 9999; + + await expect(service.getOrdersByPantry(pantryId)).rejects.toThrow( + new NotFoundException(`Pantry ${pantryId} not found`), + ); + }); }); describe('updateTrackingCostInfo', () => { @@ -384,13 +395,6 @@ describe('OrdersService', () => { const orderId = 4; const order = await service.findOne(orderId); - console.log('BEFORE UPDATE:', { - orderId: order.orderId, - status: order.status, - trackingLink: order.trackingLink, - shippingCost: order.shippingCost, - shippedAt: order.shippedAt, - }); expect(order.status).toEqual(OrderStatus.PENDING); expect(order.shippedAt).toBeNull(); @@ -398,13 +402,7 @@ describe('OrdersService', () => { await service.updateTrackingCostInfo(orderId, trackingCostDto); const updatedOrder = await service.findOne(orderId); - console.log('AFTER UPDATE:', { - orderId: updatedOrder.orderId, - status: updatedOrder.status, - trackingLink: updatedOrder.trackingLink, - shippingCost: updatedOrder.shippingCost, - shippedAt: updatedOrder.shippedAt, - }); + expect(updatedOrder.status).toEqual(OrderStatus.SHIPPED); expect(updatedOrder.shippedAt).toBeDefined(); }); diff --git a/apps/backend/src/orders/order.service.ts b/apps/backend/src/orders/order.service.ts index 0746d83a..8600e428 100644 --- a/apps/backend/src/orders/order.service.ts +++ b/apps/backend/src/orders/order.service.ts @@ -93,6 +93,10 @@ export class OrdersService { async findOrderPantry(orderId: number): Promise { const request = await this.findOrderFoodRequest(orderId); + if (!request) { + throw new NotFoundException(`Request for order ${orderId} not found`); + } + const pantry = await this.pantryRepo.findOneBy({ pantryId: request.pantryId, }); From f457d01d6012e3ffe4655cd4d9067431ac108226 Mon Sep 17 00:00:00 2001 From: amywng <147568742+amywng@users.noreply.github.com> Date: Thu, 12 Feb 2026 16:17:50 -0500 Subject: [PATCH 6/9] remove requestId and shippedBy columns from entity, rename shippedBy to foodManufacturerId, fix tests --- .../src/foodRequests/request.service.spec.ts | 54 ++----------------- .../src/foodRequests/request.service.ts | 12 +---- .../1769990652833-UpdateOrderEntity.ts | 4 +- apps/backend/src/orders/order.entity.ts | 12 ++--- apps/backend/src/orders/order.service.spec.ts | 15 +----- apps/backend/src/orders/order.service.ts | 6 +-- .../src/pantries/pantries.controller.spec.ts | 4 -- apps/frontend/src/types/types.ts | 4 +- 8 files changed, 14 insertions(+), 97 deletions(-) diff --git a/apps/backend/src/foodRequests/request.service.spec.ts b/apps/backend/src/foodRequests/request.service.spec.ts index 6e2f3a76..78ba93b0 100644 --- a/apps/backend/src/foodRequests/request.service.spec.ts +++ b/apps/backend/src/foodRequests/request.service.spec.ts @@ -105,8 +105,6 @@ describe('RequestsService', () => { describe('getOrderDetails', () => { it('should return mapped order details for a valid requestId', async () => { - const requestId = 1; - const mockOrders: Partial[] = [ { orderId: 10, @@ -155,7 +153,7 @@ describe('RequestsService', () => { mockRequest as FoodRequest, ); - const result = await service.getOrderDetails(requestId); + const result = await service.getOrderDetails(mockRequest.requestId); expect(result).toEqual([ { @@ -190,7 +188,7 @@ describe('RequestsService', () => { ]); expect(mockOrdersRepository.find).toHaveBeenCalledWith({ - where: { requestId }, + where: { request: { requestId: mockRequest.requestId } }, relations: { foodManufacturer: true, allocations: { @@ -219,7 +217,7 @@ describe('RequestsService', () => { const result = await service.getOrderDetails(requestId); expect(result).toEqual([]); expect(mockOrdersRepository.find).toHaveBeenCalledWith({ - where: { requestId }, + where: { request: { requestId } }, relations: { foodManufacturer: true, allocations: { @@ -337,9 +335,6 @@ describe('RequestsService', () => { const mockOrder: Partial = { orderId: 1, request: null, - requestId: 1, - foodManufacturer: null, - shippedBy: 1, status: OrderStatus.SHIPPED, createdAt: new Date(), shippedAt: new Date(), @@ -446,48 +441,5 @@ describe('RequestsService', () => { relations: ['orders'], }); }); - - it('should throw an error if the order does not have a food manufacturer', async () => { - const mockOrder: Partial = { - orderId: 1, - request: null, - requestId: 1, - foodManufacturer: null, - shippedBy: null, - status: OrderStatus.SHIPPED, - createdAt: new Date(), - shippedAt: new Date(), - deliveredAt: null, - }; - const mockRequest2: Partial = { - ...mockRequest, - orders: [mockOrder] as Order[], - }; - - const requestId = 1; - const deliveryDate = new Date(); - const feedback = 'Good delivery!'; - const photos = ['photo1.jpg', 'photo2.jpg']; - - mockRequestsRepository.findOne.mockResolvedValueOnce( - mockRequest2 as FoodRequest, - ); - - await expect( - service.updateDeliveryDetails( - requestId, - deliveryDate, - feedback, - photos, - ), - ).rejects.toThrow( - 'No associated food manufacturer found for an associated order', - ); - - expect(mockRequestsRepository.findOne).toHaveBeenCalledWith({ - where: { requestId }, - relations: ['orders'], - }); - }); }); }); diff --git a/apps/backend/src/foodRequests/request.service.ts b/apps/backend/src/foodRequests/request.service.ts index 80093c58..d8765ce7 100644 --- a/apps/backend/src/foodRequests/request.service.ts +++ b/apps/backend/src/foodRequests/request.service.ts @@ -42,7 +42,7 @@ export class RequestsService { } const orders = await this.orderRepo.find({ - where: { requestId }, + where: { request: { requestId } }, relations: { foodManufacturer: true, allocations: { @@ -134,16 +134,6 @@ export class RequestsService { ); } - const orders = request.orders; - - for (const order of orders) { - if (!order.shippedBy) { - throw new NotFoundException( - 'No associated food manufacturer found for an associated order', - ); - } - } - request.feedback = feedback; request.dateReceived = deliveryDate; request.photos = photos; diff --git a/apps/backend/src/migrations/1769990652833-UpdateOrderEntity.ts b/apps/backend/src/migrations/1769990652833-UpdateOrderEntity.ts index 6ebe4a74..cad6fa61 100644 --- a/apps/backend/src/migrations/1769990652833-UpdateOrderEntity.ts +++ b/apps/backend/src/migrations/1769990652833-UpdateOrderEntity.ts @@ -13,7 +13,7 @@ export class UpdateOrderEntity1769990652833 implements MigrationInterface { WHERE status = 'delivered' OR status = 'shipped' AND shipped_at IS NOT NULL; ALTER TABLE orders - ALTER COLUMN shipped_by DROP NOT NULL; + RENAME COLUMN shipped_by TO food_manufacturer_id; `); } @@ -24,7 +24,7 @@ export class UpdateOrderEntity1769990652833 implements MigrationInterface { DROP COLUMN IF EXISTS shipping_cost; ALTER TABLE orders - ALTER COLUMN shipped_by SET NOT NULL; + RENAME COLUMN food_manufacturer_id TO shipped_by; `); } } diff --git a/apps/backend/src/orders/order.entity.ts b/apps/backend/src/orders/order.entity.ts index 32145287..39d4f3be 100644 --- a/apps/backend/src/orders/order.entity.ts +++ b/apps/backend/src/orders/order.entity.ts @@ -24,18 +24,12 @@ export class Order { }) request!: FoodRequest; - @Column({ name: 'request_id' }) - requestId!: number; - - @ManyToOne(() => FoodManufacturer, { nullable: true }) + @ManyToOne(() => FoodManufacturer, { nullable: false }) @JoinColumn({ - name: 'shipped_by', + name: 'food_manufacturer_id', referencedColumnName: 'foodManufacturerId', }) - foodManufacturer?: FoodManufacturer; - - @Column({ name: 'shipped_by', nullable: true }) - shippedBy?: number; + foodManufacturer!: FoodManufacturer; @Column({ name: 'status', diff --git a/apps/backend/src/orders/order.service.spec.ts b/apps/backend/src/orders/order.service.spec.ts index e0e8f195..d402a80a 100644 --- a/apps/backend/src/orders/order.service.spec.ts +++ b/apps/backend/src/orders/order.service.spec.ts @@ -170,7 +170,7 @@ describe('OrdersService', () => { expect(order).toBeDefined(); expect(order.request).toBeDefined(); - expect(order.requestId).toBe(1); + expect(order.request.requestId).toBe(1); }); it('throws NotFoundException for non-existent order', async () => { @@ -219,18 +219,6 @@ describe('OrdersService', () => { new NotFoundException('Order 9999 not found'), ); }); - - it('throws NotFoundException if order has no FM assigned', async () => { - await testDataSource.query( - `UPDATE "orders" SET shipped_by = NULL WHERE order_id = 4`, - ); - - await expect(service.findOrderFoodManufacturer(4)).rejects.toThrow( - new NotFoundException( - 'Order 4 does not have a food manufacturer assigned', - ), - ); - }); }); describe('updateStatus', () => { @@ -239,7 +227,6 @@ describe('OrdersService', () => { const order = await service.findOne(orderId); expect(order.status).toEqual(OrderStatus.SHIPPED); - expect(order.shippedBy).toBeDefined(); expect(order.shippedAt).toBeDefined(); await service.updateStatus(orderId, OrderStatus.DELIVERED); diff --git a/apps/backend/src/orders/order.service.ts b/apps/backend/src/orders/order.service.ts index 8600e428..97a0ecee 100644 --- a/apps/backend/src/orders/order.service.ts +++ b/apps/backend/src/orders/order.service.ts @@ -20,6 +20,8 @@ export class OrdersService { @InjectRepository(Pantry) private pantryRepo: Repository, ) {} + // TODO: when order is created, set FM + async getAll(filters?: { status?: string; pantryNames?: string[] }) { const qb = this.repo .createQueryBuilder('order') @@ -79,7 +81,7 @@ export class OrdersService { validateId(requestId, 'Request'); const order = await this.repo.findOne({ - where: { requestId }, + where: { request: { requestId } }, relations: ['request'], }); @@ -140,13 +142,11 @@ export class OrdersService { async updateStatus(orderId: number, newStatus: OrderStatus) { validateId(orderId, 'Order'); - // TODO: Once we start navigating to proper food manufacturer page, change the 1 to be the proper food manufacturer id await this.repo .createQueryBuilder() .update(Order) .set({ status: newStatus as OrderStatus, - shippedBy: 1, shippedAt: newStatus === OrderStatus.SHIPPED ? new Date() : undefined, deliveredAt: newStatus === OrderStatus.DELIVERED ? new Date() : undefined, diff --git a/apps/backend/src/pantries/pantries.controller.spec.ts b/apps/backend/src/pantries/pantries.controller.spec.ts index 41cac9cb..352d8ee3 100644 --- a/apps/backend/src/pantries/pantries.controller.spec.ts +++ b/apps/backend/src/pantries/pantries.controller.spec.ts @@ -209,13 +209,9 @@ describe('PantriesController', () => { const mockOrders: Partial[] = [ { orderId: 26, - requestId: 26, - shippedBy: 32, }, { orderId: 27, - requestId: 27, - shippedBy: 33, }, ]; diff --git a/apps/frontend/src/types/types.ts b/apps/frontend/src/types/types.ts index 9156ecf5..d15da645 100644 --- a/apps/frontend/src/types/types.ts +++ b/apps/frontend/src/types/types.ts @@ -192,9 +192,7 @@ export interface FoodRequest { export interface Order { orderId: number; request: FoodRequest; - requestId: number; - foodManufacturer?: FoodManufacturer; - shippedBy?: number; + foodManufacturer: FoodManufacturer; status: OrderStatus; createdAt: string; shippedAt?: Date; From a7bee848ed7af7c1c183636dabe1a7cd52f92aa7 Mon Sep 17 00:00:00 2001 From: amywng <147568742+amywng@users.noreply.github.com> Date: Thu, 12 Feb 2026 23:50:34 -0500 Subject: [PATCH 7/9] review comments --- .../src/foodRequests/request.service.spec.ts | 8 +++++--- apps/backend/src/foodRequests/request.service.ts | 2 +- apps/backend/src/orders/order.controller.spec.ts | 15 --------------- apps/backend/src/orders/order.entity.ts | 6 ++++++ apps/backend/src/orders/order.service.spec.ts | 2 +- apps/backend/src/orders/order.service.ts | 2 +- .../src/pantries/pantries.controller.spec.ts | 4 ++++ apps/frontend/src/types/types.ts | 2 ++ 8 files changed, 20 insertions(+), 21 deletions(-) diff --git a/apps/backend/src/foodRequests/request.service.spec.ts b/apps/backend/src/foodRequests/request.service.spec.ts index 78ba93b0..1eb21b69 100644 --- a/apps/backend/src/foodRequests/request.service.spec.ts +++ b/apps/backend/src/foodRequests/request.service.spec.ts @@ -105,6 +105,8 @@ describe('RequestsService', () => { describe('getOrderDetails', () => { it('should return mapped order details for a valid requestId', async () => { + const requestId = 1; + const mockOrders: Partial[] = [ { orderId: 10, @@ -153,7 +155,7 @@ describe('RequestsService', () => { mockRequest as FoodRequest, ); - const result = await service.getOrderDetails(mockRequest.requestId); + const result = await service.getOrderDetails(requestId); expect(result).toEqual([ { @@ -188,7 +190,7 @@ describe('RequestsService', () => { ]); expect(mockOrdersRepository.find).toHaveBeenCalledWith({ - where: { request: { requestId: mockRequest.requestId } }, + where: { requestId }, relations: { foodManufacturer: true, allocations: { @@ -217,7 +219,7 @@ describe('RequestsService', () => { const result = await service.getOrderDetails(requestId); expect(result).toEqual([]); expect(mockOrdersRepository.find).toHaveBeenCalledWith({ - where: { request: { requestId } }, + where: { requestId }, relations: { foodManufacturer: true, allocations: { diff --git a/apps/backend/src/foodRequests/request.service.ts b/apps/backend/src/foodRequests/request.service.ts index d8765ce7..c74b2f87 100644 --- a/apps/backend/src/foodRequests/request.service.ts +++ b/apps/backend/src/foodRequests/request.service.ts @@ -42,7 +42,7 @@ export class RequestsService { } const orders = await this.orderRepo.find({ - where: { request: { requestId } }, + where: { requestId }, relations: { foodManufacturer: true, allocations: { diff --git a/apps/backend/src/orders/order.controller.spec.ts b/apps/backend/src/orders/order.controller.spec.ts index baf91fde..9f84f195 100644 --- a/apps/backend/src/orders/order.controller.spec.ts +++ b/apps/backend/src/orders/order.controller.spec.ts @@ -135,21 +135,6 @@ describe('OrdersController', () => { expect(result).toEqual(mockPantries[0] as Pantry); expect(mockOrdersService.findOrderPantry).toHaveBeenCalledWith(orderId); }); - - it('should throw for non-numeric input', async () => { - const invalidInput = NaN; - mockOrdersService.findOrderPantry.mockRejectedValue( - new BadRequestException( - 'Validation failed (numeric string is expected)', - ), - ); - - await expect(controller.getPantryFromOrder(invalidInput)).rejects.toThrow( - new BadRequestException( - 'Validation failed (numeric string is expected)', - ), - ); - }); }); describe('getRequestFromOrder', () => { diff --git a/apps/backend/src/orders/order.entity.ts b/apps/backend/src/orders/order.entity.ts index 39d4f3be..2913ff15 100644 --- a/apps/backend/src/orders/order.entity.ts +++ b/apps/backend/src/orders/order.entity.ts @@ -24,6 +24,9 @@ export class Order { }) request!: FoodRequest; + @Column({ name: 'request_id' }) + requestId!: number; + @ManyToOne(() => FoodManufacturer, { nullable: false }) @JoinColumn({ name: 'food_manufacturer_id', @@ -31,6 +34,9 @@ export class Order { }) foodManufacturer!: FoodManufacturer; + @Column({ name: 'food_manufacturer_id' }) + foodManufacturerId!: number; + @Column({ name: 'status', type: 'enum', diff --git a/apps/backend/src/orders/order.service.spec.ts b/apps/backend/src/orders/order.service.spec.ts index d402a80a..808ef510 100644 --- a/apps/backend/src/orders/order.service.spec.ts +++ b/apps/backend/src/orders/order.service.spec.ts @@ -170,7 +170,7 @@ describe('OrdersService', () => { expect(order).toBeDefined(); expect(order.request).toBeDefined(); - expect(order.request.requestId).toBe(1); + expect(order.requestId).toBe(1); }); it('throws NotFoundException for non-existent order', async () => { diff --git a/apps/backend/src/orders/order.service.ts b/apps/backend/src/orders/order.service.ts index 97a0ecee..812c6e03 100644 --- a/apps/backend/src/orders/order.service.ts +++ b/apps/backend/src/orders/order.service.ts @@ -81,7 +81,7 @@ export class OrdersService { validateId(requestId, 'Request'); const order = await this.repo.findOne({ - where: { request: { requestId } }, + where: { requestId }, relations: ['request'], }); diff --git a/apps/backend/src/pantries/pantries.controller.spec.ts b/apps/backend/src/pantries/pantries.controller.spec.ts index 352d8ee3..c0d94332 100644 --- a/apps/backend/src/pantries/pantries.controller.spec.ts +++ b/apps/backend/src/pantries/pantries.controller.spec.ts @@ -209,9 +209,13 @@ describe('PantriesController', () => { const mockOrders: Partial[] = [ { orderId: 26, + requestId: 26, + foodManufacturerId: 32, }, { orderId: 27, + requestId: 27, + foodManufacturerId: 33, }, ]; diff --git a/apps/frontend/src/types/types.ts b/apps/frontend/src/types/types.ts index d15da645..7fc911e6 100644 --- a/apps/frontend/src/types/types.ts +++ b/apps/frontend/src/types/types.ts @@ -192,7 +192,9 @@ export interface FoodRequest { export interface Order { orderId: number; request: FoodRequest; + requestId: number; foodManufacturer: FoodManufacturer; + foodManufacturerId: number; status: OrderStatus; createdAt: string; shippedAt?: Date; From 0c4d85df531281fc3abeb3d0448960d968452145 Mon Sep 17 00:00:00 2001 From: amywng <147568742+amywng@users.noreply.github.com> Date: Thu, 12 Feb 2026 23:52:58 -0500 Subject: [PATCH 8/9] remove FM check bc order should always have FM --- apps/backend/src/orders/order.service.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/apps/backend/src/orders/order.service.ts b/apps/backend/src/orders/order.service.ts index 812c6e03..2c52a788 100644 --- a/apps/backend/src/orders/order.service.ts +++ b/apps/backend/src/orders/order.service.ts @@ -131,11 +131,7 @@ export class OrdersService { if (!order) { throw new NotFoundException(`Order ${orderId} not found`); } - if (!order.foodManufacturer) { - throw new NotFoundException( - `Order ${orderId} does not have a food manufacturer assigned`, - ); - } + return order.foodManufacturer; } From e1e348a7ac097de382ba507212e6ce4a0d0da19e Mon Sep 17 00:00:00 2001 From: amywng <147568742+amywng@users.noreply.github.com> Date: Thu, 12 Feb 2026 23:55:01 -0500 Subject: [PATCH 9/9] remove FM check bc order should always have FM --- apps/backend/src/orders/order.service.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/backend/src/orders/order.service.ts b/apps/backend/src/orders/order.service.ts index 2c52a788..b7af3beb 100644 --- a/apps/backend/src/orders/order.service.ts +++ b/apps/backend/src/orders/order.service.ts @@ -131,7 +131,6 @@ export class OrdersService { if (!order) { throw new NotFoundException(`Order ${orderId} not found`); } - return order.foodManufacturer; }