-
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
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, | ||
|
|
||
| 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,43 @@ 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', '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<Pantry[]> { | ||
| pantryIds.forEach((id) => validateId(id, 'Pantry')); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,35 @@ | ||
| export interface 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. I think we are going to need more info than this for our approved pantry response. For one, all these pantries are approved so we shouldnt need the status. Additionally, check out the Figma for the frontend: https://www.figma.com/design/brc5luMhizIFp893XIutYe/SP26---SSF-Designs?node-id=756-11085&t=3UiKr0MdYxCcdUUK-0 The modal that pops up with Pantry Details should tell you what information we need. |
||
| 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; | ||
|
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. This should use the enum |
||
| allergenClients: string; | ||
| status: string; | ||
|
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. Same here |
||
| 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', | ||
|
|
||
| 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?