mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 18:01:08 -05:00
Refactor to increase readability for getting whitelist objects
This commit is contained in:
17
app/service/utils.py
Normal file
17
app/service/utils.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from app.models import (
|
||||
ServiceWhitelist,
|
||||
MOBILE_TYPE, EMAIL_TYPE)
|
||||
|
||||
|
||||
def get_recipients_from_request(request_json, key, type):
|
||||
return [(type, recipient) for recipient in request_json.get(key)]
|
||||
|
||||
|
||||
def get_whitelist_objects(service_id, request_json):
|
||||
return [
|
||||
ServiceWhitelist.from_string(service_id, type, recipient)
|
||||
for type, recipient in (
|
||||
get_recipients_from_request(request_json, 'phone_numbers', MOBILE_TYPE) +
|
||||
get_recipients_from_request(request_json, 'email_addresses', EMAIL_TYPE)
|
||||
)
|
||||
]
|
||||
Reference in New Issue
Block a user