Files
notifications-api/app/dao/letter_branding_dao.py
Leo Hemsted 478de8bb8e fix new services being assigned to wrong letter branding
when creating a service, the api accepts a `service_domain` field that
it uses to populate the letter branding - if the service domain is
known to match an existing letter branding option, use that
automatically. However, the admin currently doesn't know about this
field yet so doesn't pass anything through - the api erroneously
searches the DB for letter branding with a domain of None - which they
currently all have.

This meant that when services were created, their letter branding was
set to the most recent row in the DB (that matched None).
2019-02-11 11:46:33 +00:00

34 lines
933 B
Python

from app import db
from app.dao.dao_utils import transactional
from app.models import LetterBranding
def dao_get_letter_branding_by_id(letter_branding_id):
return LetterBranding.query.filter(LetterBranding.id == letter_branding_id).one()
def dao_get_letter_branding_by_domain(domain):
if not domain:
return None
return LetterBranding.query.filter(
LetterBranding.domain == domain
).first()
def dao_get_all_letter_branding():
return LetterBranding.query.order_by(LetterBranding.name).all()
@transactional
def dao_create_letter_branding(letter_branding):
db.session.add(letter_branding)
@transactional
def dao_update_letter_branding(letter_branding_id, **kwargs):
letter_branding = LetterBranding.query.get(letter_branding_id)
for key, value in kwargs.items():
setattr(letter_branding, key, value or None)
db.session.add(letter_branding)
return letter_branding