mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 01:41:05 -05:00
code review feedback
This commit is contained in:
@@ -36,13 +36,9 @@ def expire_api_key(service_id, api_key_id):
|
||||
|
||||
def get_model_api_keys(service_id, id=None):
|
||||
if id:
|
||||
return (
|
||||
db.session.execute(
|
||||
select(ApiKey).filter_by(id=id, service_id=service_id, expiry_date=None)
|
||||
)
|
||||
.scalars()
|
||||
.one()
|
||||
)
|
||||
return db.session.execute(
|
||||
select(ApiKey).where(id=id, service_id=service_id, expiry_date=None)
|
||||
).one()
|
||||
seven_days_ago = utc_now() - timedelta(days=7)
|
||||
return (
|
||||
db.session.execute(
|
||||
@@ -63,13 +59,9 @@ def get_unsigned_secrets(service_id):
|
||||
"""
|
||||
This method can only be exposed to the Authentication of the api calls.
|
||||
"""
|
||||
api_keys = (
|
||||
db.session.execute(
|
||||
select(ApiKey).filter_by(service_id=service_id, expiry_date=None)
|
||||
)
|
||||
.scalars()
|
||||
.all()
|
||||
)
|
||||
api_keys = db.session.execute(
|
||||
select(ApiKey).where(service_id=service_id, expiry_date=None)
|
||||
).all()
|
||||
keys = [x.secret for x in api_keys]
|
||||
return keys
|
||||
|
||||
@@ -78,9 +70,7 @@ def get_unsigned_secret(key_id):
|
||||
"""
|
||||
This method can only be exposed to the Authentication of the api calls.
|
||||
"""
|
||||
api_key = (
|
||||
db.session.execute(select(ApiKey).filter_by(id=key_id, expiry_date=None))
|
||||
.scalars()
|
||||
.one()
|
||||
)
|
||||
api_key = db.session.execute(
|
||||
select(ApiKey).where(id=key_id, expiry_date=None)
|
||||
).one()
|
||||
return api_key.secret
|
||||
|
||||
@@ -72,7 +72,12 @@ def dao_create_notification(notification):
|
||||
# notify-api-742 remove phone numbers from db
|
||||
notification.to = "1"
|
||||
notification.normalised_to = "1"
|
||||
db.session.add(notification)
|
||||
|
||||
# notify-api-1454 insert only if it doesn't exist
|
||||
stmt = select(Notification).where(Notification.id == notification.id)
|
||||
result = db.session.execute(stmt).scalar()
|
||||
if result is None:
|
||||
db.session.add(notification)
|
||||
|
||||
|
||||
def country_records_delivery(phone_prefix):
|
||||
@@ -106,6 +111,16 @@ def _update_notification_status(
|
||||
return notification
|
||||
|
||||
|
||||
def update_notification_message_id(notification_id, message_id):
|
||||
stmt = (
|
||||
update(Notification)
|
||||
.where(Notification.id == notification_id)
|
||||
.values(message_id=message_id)
|
||||
)
|
||||
db.session.execute(stmt)
|
||||
db.session.commit()
|
||||
|
||||
|
||||
@autocommit
|
||||
def update_notification_status_by_id(
|
||||
notification_id, status, sent_by=None, provider_response=None, carrier=None
|
||||
|
||||
Reference in New Issue
Block a user