Skip to content

Commit

Permalink
fix(import): add only new types for user
Browse files Browse the repository at this point in the history
  • Loading branch information
thekaveman committed Aug 17, 2023
1 parent d1ce66c commit 82aad05
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions eligibility_server/db/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def import_csv_users(csv_path, remote):
temp_csv.close()


def save_user(sub: str, name: str, types: str):
def save_user(sub: str, name: str, types: list):
"""
Add a user to the database User table
Expand All @@ -122,11 +122,13 @@ def save_user(sub: str, name: str, types: str):
"""

user = User.query.filter_by(sub=sub, name=name).first() or User(sub=sub, name=name)
eligibility_types = [Eligibility.query.filter_by(name=type).first() or Eligibility(name=type) for type in types]
user.types.extend(eligibility_types)
eligibility_types = [Eligibility.query.filter_by(name=t).first() or Eligibility(name=t) for t in types]
new_types = [t for t in eligibility_types if t not in user.types]
if any(new_types):
user.types.extend(new_types)

db.session.add(user)
db.session.add_all(eligibility_types)
db.session.add_all(new_types)

db.session.commit()

Expand Down

0 comments on commit 82aad05

Please sign in to comment.