update
This commit is contained in:
@@ -15,14 +15,29 @@ from layercake.dynamodb import (
|
||||
User = TypedDict('User', {'id': str, 'name': str, 'cpf': str})
|
||||
|
||||
|
||||
class CPFConflictError(BadRequestError):
|
||||
def __init__(self, *_):
|
||||
super().__init__('CPF already exists')
|
||||
|
||||
|
||||
class RateLimitError(BadRequestError):
|
||||
def __init__(self, *_):
|
||||
super().__init__('Update limit reached')
|
||||
|
||||
|
||||
class EmailConflictError(BadRequestError):
|
||||
def __init__(self, *_):
|
||||
super().__init__('Email already exists')
|
||||
|
||||
|
||||
def update_user(
|
||||
data: User,
|
||||
obj: User,
|
||||
/,
|
||||
*,
|
||||
persistence_layer: DynamoDBPersistenceLayer,
|
||||
) -> bool:
|
||||
now_ = now()
|
||||
user = SimpleNamespace(**data)
|
||||
user = SimpleNamespace(**obj)
|
||||
# Get the user's CPF, if it exists.
|
||||
old_cpf = persistence_layer.collection.get_item(
|
||||
KeyPair(
|
||||
@@ -46,15 +61,11 @@ def update_user(
|
||||
cond_expr='attribute_exists(sk)',
|
||||
)
|
||||
|
||||
class RateLimitError(BadRequestError):
|
||||
def __init__(self, msg: str):
|
||||
super().__init__('Update limit reached')
|
||||
|
||||
# Prevent the user from updating more than once every 24 hours
|
||||
transact.put(
|
||||
item={
|
||||
'id': user.id,
|
||||
'sk': 'rate_limit#user_update',
|
||||
'sk': 'RATE_LIMIT#USER_UPDATE',
|
||||
'created_at': now_,
|
||||
'ttl': ttl(start_dt=now_ + timedelta(hours=24)),
|
||||
},
|
||||
@@ -62,10 +73,6 @@ def update_user(
|
||||
cond_expr='attribute_not_exists(sk)',
|
||||
)
|
||||
|
||||
class CPFConflictError(BadRequestError):
|
||||
def __init__(self, msg: str):
|
||||
super().__init__('CPF already exists')
|
||||
|
||||
if user.cpf != old_cpf:
|
||||
transact.put(
|
||||
item={
|
||||
@@ -114,10 +121,6 @@ def add_email(
|
||||
cond_expr='attribute_not_exists(sk)',
|
||||
)
|
||||
|
||||
class EmailConflictError(BadRequestError):
|
||||
def __init__(self, msg: str):
|
||||
super().__init__('Email already exists')
|
||||
|
||||
# Prevent duplicate emails
|
||||
transact.put(
|
||||
item={
|
||||
@@ -133,7 +136,7 @@ def add_email(
|
||||
return True
|
||||
|
||||
|
||||
def del_email(
|
||||
def remove_email(
|
||||
id: str,
|
||||
email: str,
|
||||
/,
|
||||
@@ -207,7 +210,7 @@ def set_email_as_primary(
|
||||
return True
|
||||
|
||||
|
||||
def del_org_member(
|
||||
def remove_org_member(
|
||||
id: str,
|
||||
*,
|
||||
org_id: str,
|
||||
|
||||
Reference in New Issue
Block a user