forked from Code-4-Community/scaffolding
-
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
Open
swarkewalia
wants to merge
25
commits into
main
Choose a base branch
from
sk/SSF-97-pantry-management-backend
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
62ca4fb
get approved and update volunteer endpoints
swarkewalia 8907ee8
merge main
swarkewalia 08d4047
merge
swarkewalia d2aef46
merge fixes
swarkewalia 63fa43a
fix typeorm
swarkewalia 265bad6
merge fix
swarkewalia 1c948a7
Merge branch 'sk/SSF-97-pantry-management-backend' of https://github.…
swarkewalia ab18d04
Merge branch 'main' of https://github.com/Code-4-Community/ssf into s…
swarkewalia 4256a27
Merge branch 'sk/SSF-97-pantry-management-backend' of https://github.…
swarkewalia fb5ac86
merge fix
swarkewalia 3489633
gitignore fix
swarkewalia 72fc25d
git ignore fix 2
swarkewalia ddda63f
auth service fix
swarkewalia ba519d2
extra files fixes
swarkewalia 1681f42
originally changed files
swarkewalia fe9f0fd
updated package.json
swarkewalia b1fffbb
prettier
swarkewalia 0f9df9c
fixed yarn.lock
swarkewalia af4fea6
add more approved pantry info
swarkewalia 66a7677
Merge branch 'main' into sk/SSF-97-pantry-management-backend
swarkewalia 85a317f
get endpoint test
swarkewalia 0094616
Merge branch 'sk/SSF-97-pantry-management-backend' of https://github.…
swarkewalia 842ccf0
updatepantryvolunteers endpoint
swarkewalia 8f25130
updates
swarkewalia ae4f126
more changes
swarkewalia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -220,4 +220,4 @@ export class PantryApplicationDto { | |
| @IsOptional() | ||
| @IsBoolean() | ||
| newsletterSubscription?: boolean; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: number[], | ||
swarkewalia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ): Promise<void> { | ||
| return this.pantriesService.updatePantryVolunteers(pantryId, volunteerIds); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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')); | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,4 +69,4 @@ export const USPhoneInput: React.FC<USPhoneInputProps> = ({ | |
| {...inputProps} | ||
| /> | ||
| ); | ||
| }; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,4 +14,4 @@ root.render( | |
| <App /> | ||
| </ChakraProvider> | ||
| </StrictMode>, | ||
| ); | ||
| ); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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?