diff --git a/apps/backend/src/pantries/pantries.controller.ts b/apps/backend/src/pantries/pantries.controller.ts index ee8287ce..f1f7941e 100644 --- a/apps/backend/src/pantries/pantries.controller.ts +++ b/apps/backend/src/pantries/pantries.controller.ts @@ -5,12 +5,14 @@ import { Param, ParseIntPipe, Post, + Put, ValidationPipe, } from '@nestjs/common'; import { Pantry } from './pantries.entity'; import { PantriesService } from './pantries.service'; import { PantryApplicationDto } from './dtos/pantry-application.dto'; import { ApiBody } from '@nestjs/swagger'; +import { ApprovedPantryResponse } from './types'; import { Activity, AllergensConfidence, @@ -34,6 +36,11 @@ export class PantriesController { return this.pantriesService.getPendingPantries(); } + @Get('/approved') + async getApprovedPantries(): Promise { + return this.pantriesService.getApprovedPantriesWithVolunteers(); + } + @Get('/:pantryId') async getPantry( @Param('pantryId', ParseIntPipe) pantryId: number, diff --git a/apps/backend/src/pantries/pantries.service.ts b/apps/backend/src/pantries/pantries.service.ts index a2f254ec..0d692595 100644 --- a/apps/backend/src/pantries/pantries.service.ts +++ b/apps/backend/src/pantries/pantries.service.ts @@ -7,6 +7,7 @@ import { validateId } from '../utils/validation.utils'; import { PantryStatus } from './types'; import { PantryApplicationDto } from './dtos/pantry-application.dto'; import { Role } from '../users/types'; +import { ApprovedPantryResponse } from './types'; @Injectable() export class PantriesService { @@ -110,6 +111,44 @@ export class PantriesService { await this.repo.update(id, { status: PantryStatus.DENIED }); } + + async getApprovedPantriesWithVolunteers(): Promise { + const pantries = await this.repo.find({ + where: { status: PantryStatus.APPROVED }, + relations: ['pantryUser', 'volunteers'], + }); + + return pantries.map((pantry) => ({ + pantryId: pantry.pantryId, + pantryName: pantry.pantryName, + address: { + line1: pantry.shipmentAddressLine1, + line2: pantry.shipmentAddressLine2, + city: pantry.shipmentAddressCity, + state: pantry.shipmentAddressState, + zip: pantry.shipmentAddressZip, + country: pantry.shipmentAddressCountry, + }, + contactInfo: { + firstName: pantry.pantryUser.firstName, + lastName: pantry.pantryUser.lastName, + email: pantry.pantryUser.email, + phone: pantry.pantryUser.phone, + }, + refrigeratedDonation: pantry.refrigeratedDonation, + allergenClients: pantry.allergenClients, + status: pantry.status, + dateApplied: pantry.dateApplied, + assignedVolunteers: (pantry.volunteers || []).map((volunteer) => ({ + userId: volunteer.id, + name: `${volunteer.firstName} ${volunteer.lastName}`, + email: volunteer.email, + phone: volunteer.phone, + role: volunteer.role, + })), + })); + } + async findByIds(pantryIds: number[]): Promise { pantryIds.forEach((id) => validateId(id, 'Pantry')); diff --git a/apps/backend/src/pantries/types.ts b/apps/backend/src/pantries/types.ts index cdf8b671..16c41f4f 100644 --- a/apps/backend/src/pantries/types.ts +++ b/apps/backend/src/pantries/types.ts @@ -1,3 +1,34 @@ +export interface ApprovedPantryResponse { + pantryId: number; + pantryName: string; + address: { + line1: string; + line2: string | null; + city: string; + state: string; + zip: string; + country: string | null; + }; + contactInfo: { + firstName: string; + lastName: string; + email: string; + phone: string; + }; + refrigeratedDonation: string; + allergenClients: string; + status: string; + dateApplied: Date; + assignedVolunteers: AssignedVolunteer[]; +} + +export interface AssignedVolunteer { + userId: number; + name: string; + email: string; + phone: string; + role: string; +} export enum RefrigeratedDonation { YES = 'Yes, always', NO = 'No',