Skip to content

Commit

Permalink
❌ remove default value, add is_used property
Browse files Browse the repository at this point in the history
  • Loading branch information
devmount committed Apr 17, 2024
1 parent 50f6068 commit 79b91d4
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ run-command main --help

* `download-legal` is an internal command to process privacy policy and terms of service files that will be served by the frontend.
* `update-db` runs on docker container entry, and ensures the latest db migration has run, or if it's a new db then to kickstart that.
* `create-invite-codes --n 50` is an internal command to create invite codes which can be used for registrations. The `--n` argument specifies the amount of codes generated, defaults to 50 if left empty.
* `create-invite-codes n` is an internal command to create invite codes which can be used for user registrations. The `n` argument is an integer that specifies the amount of codes to be generated.
2 changes: 1 addition & 1 deletion backend/src/appointment/commands/create_invite_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from ..dependencies.database import get_engine_and_session


def run(n: int = 50):
def run(n: int):
print(f"Generating {n} new invite codes...")

codes = [str(uuid.uuid4()) for _ in range(n)]
Expand Down
5 changes: 5 additions & 0 deletions backend/src/appointment/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,8 @@ class Invite(Base):
status = Column(Enum(InviteStatus), index=True)

subscriber = relationship("Subscriber", back_populates="invite")

@property
def is_used(self) -> bool:
"""True if the invite code is assigned to a subscriber"""
return self.subscriber_id is not None
2 changes: 1 addition & 1 deletion backend/src/appointment/database/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ def schedule_has_slot(db: Session, schedule_id: int, slot_id: int):
def use_invite_code(db: Session, code: str, subscriber_id: int):
"""set existing invite code status to revoked"""
db_invite = db.query(models.Invite).filter(models.Invite.code == code).first()
if db_invite.status == models.InviteStatus.active:
if db_invite.status == models.InviteStatus.active and not db_invite.is_used:
db_invite.subscriber_id = subscriber_id
db.commit()
db.refresh(db_invite)
Expand Down
2 changes: 1 addition & 1 deletion backend/src/appointment/routes/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ def download_legal_docs():


@router.command('create-invite-codes')
def create_app_invite_codes(n: int = 50):
def create_app_invite_codes(n: int):
create_invite_codes.run(n)

0 comments on commit 79b91d4

Please sign in to comment.