Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions apps/backend/src/foodRequests/dtos/order-details.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ export class OrderDetailsDto {
orderId: number;
status: OrderStatus;
foodManufacturerName: string;
trackingLink: string;
items: OrderItemDetailsDto[];
}
2 changes: 2 additions & 0 deletions apps/backend/src/foodRequests/request.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ describe('RequestsController', () => {
orderId: 10,
status: OrderStatus.DELIVERED,
foodManufacturerName: 'Test Manufacturer',
trackingLink: 'examplelink.com',
items: [
{
name: 'Rice',
Expand All @@ -119,6 +120,7 @@ describe('RequestsController', () => {
orderId: 11,
status: OrderStatus.PENDING,
foodManufacturerName: 'Another Manufacturer',
trackingLink: 'examplelink.com',
items: [
{
name: 'Milk',
Expand Down
1 change: 1 addition & 0 deletions apps/backend/src/foodRequests/request.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class RequestsService {
orderId: order.orderId,
status: order.status,
foodManufacturerName: order.foodManufacturer.foodManufacturerName,
trackingLink: order.trackingLink,
items: order.allocations.map((allocation) => ({
name: allocation.item.itemName,
quantity: allocation.allocatedQuantity,
Expand Down
33 changes: 33 additions & 0 deletions apps/backend/src/orders/order.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 { OrderDetailsDto } from '../foodRequests/dtos/order-details.dto';
import { FoodType } from '../donationItems/types';
import { BadRequestException, NotFoundException } from '@nestjs/common';
import { FoodManufacturer } from '../foodManufacturers/manufacturers.entity';

Expand Down Expand Up @@ -62,6 +64,22 @@ describe('OrdersController', () => {
{ allocationId: 3, orderId: 2 },
];

const mockOrderDetails: Partial<OrderDetailsDto>[] = [
{
orderId: 1,
status: OrderStatus.DELIVERED,
foodManufacturerName: 'food manufacturer 1',
trackingLink: 'example-link.com',
items: [
{
name: 'item1',
quantity: 10,
foodType: FoodType.DAIRY_FREE_ALTERNATIVES,
},
],
},
];

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [OrdersController],
Expand All @@ -78,6 +96,21 @@ describe('OrdersController', () => {
expect(controller).toBeDefined();
});

describe('getOrderDetails', () => {
it('should call ordersService.findOrderDetails and return order details', async () => {
mockOrdersService.findOrderDetails.mockResolvedValueOnce(
mockOrderDetails[0] as OrderDetailsDto,
);

const orderId = 1;

const result = await controller.getOrderDetails(orderId);

expect(result).toEqual(mockOrderDetails[0] as OrderDetailsDto);
expect(mockOrdersService.findOrderDetails).toHaveBeenCalledWith(orderId);
});
});

describe('getAllOrders', () => {
it('should call ordersService.getAll and return orders', async () => {
const status = 'pending';
Expand Down
8 changes: 8 additions & 0 deletions apps/backend/src/orders/order.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { FoodRequest } from '../foodRequests/request.entity';
import { AllocationsService } from '../allocations/allocations.service';
import { OrderStatus } from './types';
import { TrackingCostDto } from './dtos/tracking-cost.dto';
import { OrderDetailsDto } from '../foodRequests/dtos/order-details.dto';

@Controller('orders')
export class OrdersController {
Expand Down Expand Up @@ -77,6 +78,13 @@ export class OrdersController {
return this.ordersService.findOne(orderId);
}

@Get('/:orderId/order-details')
async getOrderDetails(
@Param('orderId', ParseIntPipe) orderId: number,
): Promise<OrderDetailsDto> {
return this.ordersService.findOrderDetails(orderId);
}

@Get('/order/:requestId')
async getOrderByRequestId(
@Param('requestId', ParseIntPipe) requestId: number,
Expand Down
Loading