Skip to content

Commit

Permalink
make contact reference instead of embedded
Browse files Browse the repository at this point in the history
  • Loading branch information
AungKMin committed Oct 26, 2023
1 parent 4dd39be commit e74ca13
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion backend/app/models/meal_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class MealRequest(mg.Document):
donation_datetime = mg.DateTimeField(required=True)
drop_off_location = mg.StringField(required=True)
delivery_instructions = mg.StringField(required=True)
onsite_staff = mg.ListField(mg.ObjectIdField(), required=True)
onsite_staff = mg.ListField(mg.ReferenceField(Contact), required=True)

# Timestamps
date_created = mg.DateTimeField(required=True, default=datetime.utcnow)
Expand Down
6 changes: 3 additions & 3 deletions backend/app/models/user_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class RoleInfo(mg.EmbeddedDocument):
donor_info = mg.EmbeddedDocumentField(DonorInfo)


class Contact(mg.EmbeddedDocument):
class Contact(mg.Document):
_id = mg.ObjectIdField(required=True, default=ObjectId)
name = mg.StringField(required=True)
email = mg.StringField(required=True)
Expand All @@ -41,8 +41,8 @@ class UserInfo(mg.EmbeddedDocument):
organization_coordinates = mg.GeoPointField()
role = mg.StringField(choices=USERINFO_ROLES, required=True)
role_info = mg.EmbeddedDocumentField(RoleInfo)
primary_contact = mg.EmbeddedDocumentField(Contact, required=True)
onsite_contacts = mg.EmbeddedDocumentListField(Contact, required=True)
primary_contact = mg.ReferenceField(Contact, required=True)
onsite_contacts = mg.ListField(mg.ReferenceField(Contact), required=True)
active = mg.BooleanField(default=True)

meta = {"allow_inheritance": True}
10 changes: 7 additions & 3 deletions backend/tests/unit/test_models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from app.models.user import User
from app.models.onboarding_request import OnboardingRequest
from app.models.user_info import UserInfo

from app.models.user_info import UserInfo, Contact

"""
Sample python test.
Expand Down Expand Up @@ -45,7 +44,12 @@ def test_create_user():

def test_create_onboarding_request():
status = "Pending"
user_info = UserInfo(**test_user_info)
primary_contact = Contact(**test_user_info["primary_contact"])
onsite_contacts = [Contact(**contact) for contact in test_user_info["onsite_contacts"]]
test_user_info_copy = test_user_info.copy()
test_user_info_copy["primary_contact"] = primary_contact
test_user_info_copy["onsite_contacts"] = [contact for contact in onsite_contacts]
user_info = UserInfo(**test_user_info_copy)
onboarding_request = OnboardingRequest(info=user_info, status=status)
assert onboarding_request.status == status
assert onboarding_request.info.email == test_user_info["email"]
Expand Down

0 comments on commit e74ca13

Please sign in to comment.