add typing
This commit is contained in:
@@ -83,3 +83,49 @@ def del_email(
|
||||
return persistence_layer.transact_write_items(transact)
|
||||
except ClientError:
|
||||
raise BadRequestError('Cannot remove the primary email.')
|
||||
|
||||
|
||||
def set_email_as_primary(
|
||||
id: str,
|
||||
new_email: str,
|
||||
old_email: str,
|
||||
/,
|
||||
*,
|
||||
email_verified: bool = False,
|
||||
persistence_layer: DynamoDBPersistenceLayer,
|
||||
):
|
||||
now_ = now()
|
||||
expr = 'SET email_primary = :email_primary, update_date = :update_date'
|
||||
transact = TransactItems(persistence_layer.table_name)
|
||||
|
||||
transact.update(
|
||||
key=KeyPair(id, ComposeKey(old_email, 'emails')),
|
||||
update_expr=expr,
|
||||
expr_attr_values={
|
||||
':email_primary': False,
|
||||
':update_date': now_,
|
||||
},
|
||||
)
|
||||
# Set the new email as primary
|
||||
transact.update(
|
||||
key=KeyPair(id, ComposeKey(new_email, 'emails')),
|
||||
update_expr=expr,
|
||||
expr_attr_values={
|
||||
':email_primary': True,
|
||||
':update_date': now_,
|
||||
},
|
||||
)
|
||||
transact.update(
|
||||
key=KeyPair(id, '0'),
|
||||
update_expr=(
|
||||
'SET email = :email, email_verified = :email_verified, '
|
||||
'update_date = :update_date'
|
||||
),
|
||||
expr_attr_values={
|
||||
':email': new_email,
|
||||
':email_verified': email_verified,
|
||||
':update_date': now_,
|
||||
},
|
||||
)
|
||||
|
||||
return persistence_layer.transact_write_items(transact)
|
||||
|
||||
Reference in New Issue
Block a user