-
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
7fe16c0
6aa3025
18776f3
b0591a0
f4e3893
d29748f
7a66455
7f6edf9
cf9f2b6
82ea854
e88b4bd
303c5c2
b9e4491
934e9db
9f5e2e5
ff491af
97fbb5d
994bf06
0a78425
1d25739
92f19ab
88a0f2a
15dce5d
a6cae91
5ad50d1
c0f9961
0e4a0ce
51b9b69
6831f31
33f0a11
2a5b86f
d9135a3
4449e5b
219f7b5
b1faff8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Yurika-Kan marked this conversation as resolved.
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ import { validateId } from '../utils/validation.utils'; | |
| import { ApplicationStatus } from '../shared/types'; | ||
| import { PantryApplicationDto } from './dtos/pantry-application.dto'; | ||
| import { Role } from '../users/types'; | ||
| import { ApprovedPantryResponse } from './types'; | ||
| import { PantryStats, TotalStats } from './types'; | ||
| import { userSchemaDto } from '../users/dtos/userSchema.dto'; | ||
| import { UsersService } from '../users/users.service'; | ||
|
|
@@ -362,6 +363,64 @@ export class PantriesService { | |
| await this.repo.update(id, { status: ApplicationStatus.DENIED }); | ||
| } | ||
|
|
||
| async getApprovedPantriesWithVolunteers(): Promise<ApprovedPantryResponse[]> { | ||
dburkhart07 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const pantries = await this.repo.find({ | ||
| where: { status: ApplicationStatus.APPROVED }, | ||
| relations: ['volunteers', 'pantryUser'], | ||
| }); | ||
|
|
||
| return pantries.map((pantry) => ({ | ||
|
Collaborator
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. Can you take a look at what the return from the above call to TypeORM looks like? That should likely have all the information we need, it doesn't look like this map is doing much other than copying all the fields from one object to another. If we do go with the current approach rather than just returning |
||
| pantryId: pantry.pantryId, | ||
| pantryName: pantry.pantryName, | ||
| refrigeratedDonation: pantry.refrigeratedDonation, | ||
| volunteers: (pantry.volunteers || []).map((volunteer) => ({ | ||
| userId: volunteer.id, | ||
| firstName: volunteer.firstName, | ||
| lastName: volunteer.lastName, | ||
| email: volunteer.email, | ||
| phone: volunteer.phone, | ||
| })), | ||
| })); | ||
| } | ||
|
|
||
| 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
|
||
| const users = await Promise.all( | ||
| volunteerIds.map((id) => this.usersService.findOne(id)), | ||
| ); | ||
|
|
||
| if (users.length !== volunteerIds.length) { | ||
| throw new NotFoundException('One or more users not found'); | ||
| } | ||
|
|
||
| const nonVolunteers = users.filter((user) => user.role !== Role.VOLUNTEER); | ||
|
|
||
| if (nonVolunteers.length > 0) { | ||
| throw new BadRequestException( | ||
| `Users ${nonVolunteers | ||
| .map((user) => user.id) | ||
| .join(', ')} are not volunteers`, | ||
| ); | ||
| } | ||
|
|
||
| pantry.volunteers = users; | ||
| 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,18 @@ | ||
| 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.
Collaborator
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. Sorry, there may have been some confusion here. It's fine if we have to make another API call to get the full details about a pantry when the user navigates to the "pantry details" page - we just need the info for the main table (as well as the IDs necessary to be able to navigate to the other pages)
Collaborator
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.
bringing this back - let's just return the pantry id, name, refrigerated donation, and volunteers assigned list for this backend supporting the pantry management view for the pantry details page (not part of this ticket), we can call the existing get pantry by pantryId endpoint for all these fields
Collaborator
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. Both of these interfaces look very similar to the |
||
| pantryId: number; | ||
| pantryName: string; | ||
| refrigeratedDonation: RefrigeratedDonation; | ||
| volunteers: AssignedVolunteer[]; | ||
| } | ||
|
|
||
| export interface AssignedVolunteer { | ||
Yurika-Kan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| userId: number; | ||
| firstName: string; | ||
| lastName: string; | ||
| email: string; | ||
| phone: string; | ||
| } | ||
|
|
||
| export enum RefrigeratedDonation { | ||
| YES = 'Yes, always', | ||
| NO = 'No', | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,7 @@ export interface Pantry { | |
| shipmentAddressCity: string; | ||
| shipmentAddressState: string; | ||
| shipmentAddressZip: string; | ||
| shipmentAddressCountry?: string; | ||
| shipmentAddressCountry: string; | ||
|
Collaborator
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. sorry - this should be nullable (restore previous ver) |
||
| mailingAddressLine1: string; | ||
| mailingAddressLine2?: string; | ||
| mailingAddressCity: string; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.