mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-24 00:06:16 -04:00
convert more queries
This commit is contained in:
@@ -281,11 +281,14 @@ def dao_archive_service(service_id):
|
|||||||
# .filter(Service.id == service_id)
|
# .filter(Service.id == service_id)
|
||||||
# .one()
|
# .one()
|
||||||
# )
|
# )
|
||||||
stmt = select(
|
stmt = (
|
||||||
Service).options(
|
select(Service)
|
||||||
|
.options(
|
||||||
joinedload(Service.templates).subqueryload(Template.template_redacted),
|
joinedload(Service.templates).subqueryload(Template.template_redacted),
|
||||||
joinedload(Service.api_keys),
|
joinedload(Service.api_keys),
|
||||||
).filter(Service.id == service_id)
|
)
|
||||||
|
.filter(Service.id == service_id)
|
||||||
|
)
|
||||||
service = db.session.execute(stmt).scalars().unique().one()
|
service = db.session.execute(stmt).scalars().unique().one()
|
||||||
|
|
||||||
service.active = False
|
service.active = False
|
||||||
@@ -722,14 +725,22 @@ def get_live_services_with_organization():
|
|||||||
|
|
||||||
# return query.all()
|
# return query.all()
|
||||||
|
|
||||||
stmt = select(Service.id.label("service_id"),
|
stmt = (
|
||||||
|
select(
|
||||||
|
Service.id.label("service_id"),
|
||||||
Service.name.label("service_name"),
|
Service.name.label("service_name"),
|
||||||
Organization.id.label("organization_id"),
|
Organization.id.label("organization_id"),
|
||||||
Organization.name.label("organization_name")).select_from(Service).outerjoin(Service.organization).filter(
|
Organization.name.label("organization_name"),
|
||||||
|
)
|
||||||
|
.select_from(Service)
|
||||||
|
.outerjoin(Service.organization)
|
||||||
|
.filter(
|
||||||
Service.count_as_live.is_(True),
|
Service.count_as_live.is_(True),
|
||||||
Service.active.is_(True),
|
Service.active.is_(True),
|
||||||
Service.restricted.is_(False),
|
Service.restricted.is_(False),
|
||||||
).order_by(Organization.name, Service.name)
|
)
|
||||||
|
.order_by(Organization.name, Service.name)
|
||||||
|
)
|
||||||
|
|
||||||
return db.session.execute(stmt).all()
|
return db.session.execute(stmt).all()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user