mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-31 23:26:23 -05:00
Organisation service DAO
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from app import db
|
||||
from app.dao.dao_utils import transactional
|
||||
from app.models import Organisation
|
||||
from app.models import Organisation, Service
|
||||
|
||||
|
||||
def dao_get_organisations():
|
||||
@@ -9,10 +9,20 @@ def dao_get_organisations():
|
||||
).all()
|
||||
|
||||
|
||||
def dao_get_organisation_services(organisation_id):
|
||||
return Organisation.query.filter_by(
|
||||
id=organisation_id
|
||||
).one().services
|
||||
|
||||
|
||||
def dao_get_organisation_by_id(organisation_id):
|
||||
return Organisation.query.filter_by(id=organisation_id).one()
|
||||
|
||||
|
||||
def dao_get_organisation_by_service_id(service_id):
|
||||
return Organisation.query.join(Organisation.services).filter(Service.id == service_id).first()
|
||||
|
||||
|
||||
@transactional
|
||||
def dao_create_organisation(organisation):
|
||||
db.session.add(organisation)
|
||||
@@ -23,3 +33,12 @@ def dao_update_organisation(organisation_id, **kwargs):
|
||||
return Organisation.query.filter_by(id=organisation_id).update(
|
||||
kwargs
|
||||
)
|
||||
|
||||
|
||||
@transactional
|
||||
def dao_add_service_to_organisation(service, organisation_id):
|
||||
organisation = Organisation.query.filter_by(
|
||||
id=organisation_id
|
||||
).one()
|
||||
|
||||
organisation.services.append(service)
|
||||
|
||||
Reference in New Issue
Block a user