Skip to content

Commit

Permalink
handling an edge case when a label already exists in database
Browse files Browse the repository at this point in the history
  • Loading branch information
jiji14 committed Jan 9, 2024
1 parent 3db594c commit 41fea13
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions emission/core/wrapper/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,17 @@ def insertUserCustomLabel(self, inserted_label):
key = inserted_label['key']
label = inserted_label['label']
items = user[key] if key in user else {}
items[label] = {
'createdAt': datetime.now(),
'frequency': 0,
'isActive': True,
}

# if label exists in database, chage it as 'active' label
if label in items:
items[label]['isActive'] = True
else:
items[label] = {
'createdAt': datetime.now(),
'frequency': 0,
'isActive': True,
}

get_profile_db().update_one({'user_id': self.uuid}, {'$set': {key: items}})
return self.getUserCustomLabel(key)

Expand Down

0 comments on commit 41fea13

Please sign in to comment.