-
Notifications
You must be signed in to change notification settings - Fork 0
SSF 97 pantry management backend #76
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
base: main
Are you sure you want to change the base?
Changes from all commits
62ca4fb
8907ee8
08d4047
d2aef46
63fa43a
265bad6
1c948a7
ab18d04
4256a27
fb5ac86
3489633
72fc25d
ddda63f
ba519d2
1681f42
fe9f0fd
b1fffbb
0f9df9c
af4fea6
66a7677
85a317f
0094616
842ccf0
8f25130
ae4f126
31cb4e5
20bd058
a8a3289
dc53864
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,8 +33,7 @@ npm-debug.log | |
| yarn-error.log | ||
| testem.log | ||
| /typings | ||
| .nx | ||
|
|
||
|
|
||
| # System Files | ||
| .DS_Store | ||
| Thumbs.db | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -220,4 +220,4 @@ export class PantryApplicationDto { | |
| @IsOptional() | ||
| @IsBoolean() | ||
| newsletterSubscription?: boolean; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should write a test for this as well. |
||
| async getApprovedPantries(): Promise<ApprovedPantryResponse[]> { | ||
| return this.pantriesService.getApprovedPantriesWithVolunteers(); | ||
| } | ||
|
|
||
| @Get('/:pantryId') | ||
| async getPantry( | ||
| @Param('pantryId', ParseIntPipe) pantryId: number, | ||
|
|
@@ -225,4 +232,12 @@ export class PantriesController { | |
| ): Promise<void> { | ||
| return this.pantriesService.deny(pantryId); | ||
| } | ||
|
|
||
| @Put('/:pantryId/volunteers') | ||
| async updatePantryVolunteers( | ||
| @Param('pantryId', ParseIntPipe) pantryId: number, | ||
| @Body('volunteerIds') volunteerIds: number[], | ||
| ): Promise<void> { | ||
| return this.pantriesService.updatePantryVolunteers(pantryId, volunteerIds); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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,61 @@ export class PantriesService { | |
| await this.repo.update(id, { status: PantryStatus.DENIED }); | ||
| } | ||
|
|
||
| async getApprovedPantriesWithVolunteers(): Promise<ApprovedPantryResponse[]> { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See comment in the type.ts file, this will need to change too. |
||
| const pantries = await this.repo.find({ | ||
| where: { status: PantryStatus.APPROVED }, | ||
| relations: ['pantryUser'], | ||
| }); | ||
|
|
||
| return pantries.map((pantry) => ({ | ||
| pantryId: pantry.pantryId, | ||
| pantryName: pantry.pantryName, | ||
| contactFirstName: pantry.pantryUser.firstName, | ||
| contactLastName: pantry.pantryUser.lastName, | ||
| contactEmail: pantry.pantryUser.email, | ||
| contactPhone: pantry.pantryUser.phone, | ||
| shipmentAddressLine1: pantry.shipmentAddressLine1, | ||
| shipmentAddressCity: pantry.shipmentAddressCity, | ||
| shipmentAddressZip: pantry.shipmentAddressZip, | ||
| shipmentAddressCountry: pantry.shipmentAddressCountry, | ||
| allergenClients: pantry.allergenClients, | ||
| restrictions: pantry.restrictions, | ||
| refrigeratedDonation: pantry.refrigeratedDonation, | ||
| reserveFoodForAllergic: pantry.reserveFoodForAllergic, | ||
| reservationExplanation: pantry.reservationExplanation, | ||
| dedicatedAllergyFriendly: pantry.dedicatedAllergyFriendly, | ||
| clientVisitFrequency: pantry.clientVisitFrequency, | ||
| identifyAllergensConfidence: pantry.identifyAllergensConfidence, | ||
| serveAllergicChildren: pantry.serveAllergicChildren, | ||
| activities: pantry.activities, | ||
| activitiesComments: pantry.activitiesComments, | ||
| itemsInStock: pantry.itemsInStock, | ||
| needMoreOptions: pantry.needMoreOptions, | ||
| newsletterSubscription: pantry.newsletterSubscription ?? false, | ||
| })); | ||
| } | ||
|
|
||
| async updatePantryVolunteers( | ||
| pantryId: number, | ||
| volunteerIds: number[], | ||
| ): Promise<void> { | ||
| validateId(pantryId, 'Pantry'); | ||
| volunteerIds.forEach((id) => validateId(id, 'Volunteer')); | ||
|
|
||
| const pantry = await this.repo.findOne({ | ||
| where: { pantryId }, | ||
| relations: ['volunteers'], | ||
| }); | ||
|
|
||
| if (!pantry) { | ||
| throw new NotFoundException(`Pantry with ID ${pantryId} not found`); | ||
| } | ||
|
|
||
dburkhart07 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| pantry.volunteers = volunteerIds.map((id) => ({ id } as User)); | ||
|
|
||
| await this.repo.save(pantry); | ||
| } | ||
|
|
||
| async findByIds(pantryIds: number[]): Promise<Pantry[]> { | ||
| pantryIds.forEach((id) => validateId(id, 'Pantry')); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,38 @@ | ||
| export interface ApprovedPantryResponse { | ||
dburkhart07 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| pantryId: number; | ||
| pantryName: string; | ||
| contactFirstName: string; | ||
| contactLastName: string; | ||
| contactEmail: string; | ||
| contactPhone: string; | ||
| shipmentAddressLine1: string; | ||
| shipmentAddressCity: string; | ||
| shipmentAddressZip: string; | ||
| shipmentAddressCountry?: string; | ||
| allergenClients: string; | ||
| restrictions: string[]; | ||
| refrigeratedDonation: RefrigeratedDonation; | ||
| reserveFoodForAllergic: ReserveFoodForAllergic; | ||
| reservationExplanation?: string; | ||
| dedicatedAllergyFriendly: boolean; | ||
| clientVisitFrequency?: ClientVisitFrequency; | ||
| identifyAllergensConfidence?: AllergensConfidence; | ||
| serveAllergicChildren?: ServeAllergicChildren; | ||
| activities: Activity[]; | ||
| activitiesComments?: string; | ||
| itemsInStock: string; | ||
| needMoreOptions: string; | ||
| newsletterSubscription: boolean; | ||
| } | ||
|
|
||
| export interface AssignedVolunteer { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are there two of these? |
||
| userId: number; | ||
| name: string; | ||
| email: string; | ||
| phone: string; | ||
| role: string; | ||
| } | ||
|
|
||
| export enum RefrigeratedDonation { | ||
| YES = 'Yes, always', | ||
| NO = 'No', | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,4 +69,4 @@ export const USPhoneInput: React.FC<USPhoneInputProps> = ({ | |
| {...inputProps} | ||
| /> | ||
| ); | ||
| }; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,4 +14,4 @@ root.render( | |
| <App /> | ||
| </ChakraProvider> | ||
| </StrictMode>, | ||
| ); | ||
| ); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this here? Can we get rid of it?