Skip to content

Commit f43d94d

Browse files
committed
Fix issues from deleted onsite contacts in old meal requests.
1 parent fefdb5a commit f43d94d

File tree

5 files changed

+35
-34
lines changed

5 files changed

+35
-34
lines changed

backend/app/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
def create_app(config_name):
4747
print("Environment is", config_name)
48-
if config_name != "testing":
48+
if config_name != "testing" and config_name != "development":
4949
sentry_sdk.init(
5050
dsn="https://85a9bf2fc71b287cc4e60cb9f918f034@o4507682847850496.ingest.us.sentry.io/4507801405227008",
5151
# Set traces_sample_rate to 1.0 to capture 100%

backend/app/models/meal_request.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ def validate_onsite_contacts(self):
8989
f"onsite contact {contact.id} not found or not associated with the donor organization"
9090
)
9191

92+
def _get_expanded_contacts_list(self, contacts):
93+
expanded_contacts = []
94+
for contact in contacts:
95+
# If a contact is deleted, it won't have the `to_serializable_dict` method, so we won't add it to the results
96+
if not hasattr(contact, "to_serializable_dict"):
97+
continue
98+
expanded_contacts.append(contact.to_serializable_dict())
99+
return expanded_contacts
100+
92101
def to_serializable_dict(self):
93102
"""
94103
Returns a dict representation of the document that is JSON serializable
@@ -98,15 +107,11 @@ def to_serializable_dict(self):
98107
meal_request_dict = self.to_mongo().to_dict()
99108
id = meal_request_dict.pop("_id", None)
100109
meal_request_dict["id"] = str(id)
101-
102-
contacts = [contact.to_serializable_dict() for contact in self.onsite_contacts]
110+
contacts = self._get_expanded_contacts_list(self.onsite_contacts)
103111
meal_request_dict["onsite_contacts"] = contacts
104112

105113
if self.donation_info and self.donation_info.donor_onsite_contacts:
106-
contacts = [
107-
contact.to_serializable_dict()
108-
for contact in self.donation_info.donor_onsite_contacts
109-
]
114+
contacts = self._get_expanded_contacts_list(self.donation_info.donor_onsite_contacts)
110115
meal_request_dict["donation_info"]["donor_onsite_contacts"] = contacts
111116

112117
return meal_request_dict

backend/app/services/implementations/meal_request_service.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def commit_to_meal_request(
217217

218218
meal_request_dtos.append(meal_request.to_dto())
219219
meal_request.save()
220-
donor.info.involved_meal_requests += 1
220+
donor.info.involved_meal_requests += len(meal_request_dtos)
221221
donor.save()
222222

223223
return meal_request_dtos
@@ -238,7 +238,7 @@ def cancel_donation(self, meal_request_id: str) -> MealRequestDTO:
238238
)
239239

240240
donor = User.objects(id=meal_request.donation_info.donor.id).first()
241-
donor.info.involved_meal_requests -= 1
241+
donor.info.involved_meal_requests = max(donor.info.involved_meal_requests - 1, 0)
242242
donor.save()
243243

244244
meal_request.donation_info = None
@@ -260,7 +260,7 @@ def delete_meal_request(self, meal_request_id: str) -> MealRequestDTO:
260260
raise Exception(f'Meal request "{meal_request_id}" not found')
261261

262262
requestor = User.objects(id=meal_request.requestor.id).first()
263-
requestor.info.involved_meal_requests -= 1
263+
requestor.info.involved_meal_requests = max(requestor.info.involved_meal_requests - 1, 0)
264264
requestor.save()
265265

266266
meal_request.delete()

frontend/src/components/common/OnsiteContactSection.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,6 @@ const OnsiteContactSection = ({
379379
}: OnsiteContactSectionProps): React.ReactElement => {
380380
const isWebView = useIsWebView();
381381

382-
const [showCreateModal, setShowCreateModal] = useState(false);
383382

384383
if (isWebView) {
385384
return (
@@ -554,10 +553,7 @@ const OnsiteContactSection = ({
554553
email: "",
555554
},
556555
]);
557-
return;
558556
}
559-
560-
setShowCreateModal(true);
561557
}}
562558
>
563559
+ Add another contact

frontend/src/pages/EditMealRequestForm.tsx

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -268,27 +268,29 @@ const EditMealRequestForm = ({
268268

269269
// For validation
270270
const validateData = () => {
271-
if (
272-
numberOfMeals <= 0 ||
273-
onsiteContacts.length === 0 ||
274-
onsiteContacts.some(
275-
(contact) =>
276-
!contact ||
277-
contact.name === "" ||
278-
contact.email === "" ||
279-
contact.phone === "",
280-
)
281-
) {
282-
setAttemptedSubmit(true);
283-
return false;
284-
}
285-
286271
if (isEditDonation) {
287272
if (mealDescription === "") {
288273
setAttemptedSubmit(true);
289274
return false;
290275
}
291-
}
276+
if (mealDonorOnsiteContacts.length < 0) {
277+
setAttemptedSubmit(true);
278+
return false;
279+
}
280+
} else if (
281+
numberOfMeals <= 0 ||
282+
onsiteContacts.length < 0 ||
283+
onsiteContacts.some(
284+
(contact) =>
285+
!contact ||
286+
contact.name === "" ||
287+
contact.email === "" ||
288+
contact.phone === "",
289+
)
290+
) {
291+
setAttemptedSubmit(true);
292+
return false;
293+
}
292294

293295
setAttemptedSubmit(false);
294296
return true;
@@ -426,12 +428,10 @@ const EditMealRequestForm = ({
426428
Food Description
427429
</FormLabel>
428430
<FormHelperText fontSize="xs" my={2}>
429-
Please describe a typical meal you can provide (this can be
430-
modified later)
431+
Please describe a typical meal you can provide:
431432
</FormHelperText>
432433
<Input
433-
// TODO should we change this placeholder?
434-
placeholder="Ex. 40 mac and cheeses with 9 gluten free ones. Also will donate 30 bags of cheetos."
434+
placeholder="Ex. Will be bringing 5 large cheese pizza's."
435435
value={mealDescription}
436436
onChange={(e) => setMealDescription(e.target.value)}
437437
ref={initialFocusRef}

0 commit comments

Comments
 (0)