Organisation service DAO

This commit is contained in:
Ken Tsang
2018-02-10 01:34:37 +00:00
parent 6e0e3e9f08
commit 60f96ab598
3 changed files with 89 additions and 9 deletions

View File

@@ -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)