mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-24 00:06:16 -04:00
upgrade org and template dao to sqlalchemy 2.0
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
from sqlalchemy import select
|
||||||
from sqlalchemy.sql.expression import func
|
from sqlalchemy.sql.expression import func
|
||||||
|
|
||||||
from app import db
|
from app import db
|
||||||
@@ -6,14 +7,15 @@ from app.models import Domain, Organization, Service, User
|
|||||||
|
|
||||||
|
|
||||||
def dao_get_organizations():
|
def dao_get_organizations():
|
||||||
return Organization.query.order_by(
|
stmt = select(Organization).order_by(
|
||||||
Organization.active.desc(), Organization.name.asc()
|
Organization.active.desc(), Organization.name.asc()
|
||||||
).all()
|
)
|
||||||
|
return db.session.execute(stmt).scalars().all()
|
||||||
|
|
||||||
|
|
||||||
def dao_count_organizations_with_live_services():
|
def dao_count_organizations_with_live_services():
|
||||||
return (
|
stmt = (
|
||||||
db.session.query(Organization.id)
|
select(func.count(Organization.id))
|
||||||
.join(Organization.services)
|
.join(Organization.services)
|
||||||
.filter(
|
.filter(
|
||||||
Service.active.is_(True),
|
Service.active.is_(True),
|
||||||
@@ -21,8 +23,8 @@ def dao_count_organizations_with_live_services():
|
|||||||
Service.count_as_live.is_(True),
|
Service.count_as_live.is_(True),
|
||||||
)
|
)
|
||||||
.distinct()
|
.distinct()
|
||||||
.count()
|
|
||||||
)
|
)
|
||||||
|
return db.session.execute(stmt).scalar() or 0
|
||||||
|
|
||||||
|
|
||||||
def dao_get_organization_services(organization_id):
|
def dao_get_organization_services(organization_id):
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ def _create_service_invite(invited_user, invite_link_host):
|
|||||||
redis_store.set(
|
redis_store.set(
|
||||||
f"email-personalisation-{saved_notification.id}",
|
f"email-personalisation-{saved_notification.id}",
|
||||||
json.dumps(personalisation),
|
json.dumps(personalisation),
|
||||||
ex=2*24*60*60,
|
ex=2 * 24 * 60 * 60,
|
||||||
)
|
)
|
||||||
send_notification_to_queue(saved_notification, queue=QueueNames.NOTIFY)
|
send_notification_to_queue(saved_notification, queue=QueueNames.NOTIFY)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user