Skip to content

Commit

Permalink
Merge pull request #4962 from bcgov/test-marshal-DV-4707-1
Browse files Browse the repository at this point in the history
query fixed with tuple
  • Loading branch information
divyav-aot authored Jan 4, 2024
2 parents fa51cdd + f906b1c commit 3722c05
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
11 changes: 4 additions & 7 deletions request-management-api/request_api/models/FOIMinistryRequests.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,12 +739,10 @@ def getupcominglegislativeduerecords(cls):
upcomingduerecords = []
try:
sql = """select distinct on (filenumber) filenumber, to_char(duedate, 'YYYY-MM-DD') as duedate, foiministryrequestid, version, foirequest_id, created_at, createdby from "FOIMinistryRequests" fpa
where isactive = true and duedate is not null and requeststatuslabel not in (:requeststatuslabel)
where isactive = true and duedate is not null and requeststatuslabel not in :requeststatuslabel
and duedate between NOW() - INTERVAL '7 DAY' AND NOW() + INTERVAL '7 DAY'
order by filenumber , version desc;"""
requeststatuslabel = [StateName.closed.name,StateName.redirect.name,StateName.unopened.name,StateName.intakeinprogress.name,StateName.onhold.name,StateName.archived.name]
requeststatuslabel = ','.join(str(e) for e in requeststatuslabel)
print(f"requeststatuslabel ====== {requeststatuslabel}")
requeststatuslabel = tuple([StateName.closed.name,StateName.redirect.name,StateName.unopened.name,StateName.intakeinprogress.name,StateName.onhold.name,StateName.archived.name])
rs = db.session.execute(text(sql), {'requeststatuslabel': requeststatuslabel})
for row in rs:
upcomingduerecords.append({"filenumber": row["filenumber"], "duedate": row["duedate"],"foiministryrequestid": row["foiministryrequestid"], "version": row["version"], "foirequest_id": row["foirequest_id"], "created_at": row["created_at"], "createdby": row["createdby"]})
Expand All @@ -765,13 +763,12 @@ def getupcomingdivisionduerecords(cls):
from "FOIMinistryRequestDivisions" frd
inner join (select distinct on (fpa.foiministryrequestid) foiministryrequestid, version as foiministryrequestversion, axisrequestid, filenumber, foirequest_id, requeststatusid, requeststatuslabel
from "FOIMinistryRequests" fpa
order by fpa.foiministryrequestid , fpa.version desc) fma on frd.foiministryrequest_id = fma.foiministryrequestid and frd.foiministryrequestversion_id = fma.foiministryrequestversion and fma.requeststatuslabel not in (:requeststatuslabel)
order by fpa.foiministryrequestid , fpa.version desc) fma on frd.foiministryrequest_id = fma.foiministryrequestid and frd.foiministryrequestversion_id = fma.foiministryrequestversion and fma.requeststatuslabel not in :requeststatuslabel
inner join "ProgramAreaDivisions" pad2 on frd.divisionid = pad2.divisionid
inner join "ProgramAreaDivisionStages" pads on frd.stageid = pads.stageid and frd.stageid in (5, 7, 9)
and frd.divisionduedate between NOW() - INTERVAL '7 DAY' AND NOW() + INTERVAL '7 DAY'
order by frd.foiministryrequest_id , frd.foiministryrequestversion_id desc;"""
requeststatuslabel = [StateName.closed.name,StateName.redirect.name,StateName.unopened.name,StateName.intakeinprogress.name,StateName.onhold.name,StateName.archived.name]
requeststatuslabel = ','.join(str(e) for e in requeststatuslabel)
requeststatuslabel = tuple([StateName.closed.name,StateName.redirect.name,StateName.unopened.name,StateName.intakeinprogress.name,StateName.onhold.name,StateName.archived.name])
rs = db.session.execute(text(sql), {'requeststatuslabel': requeststatuslabel})

for row in rs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ def getcommentnotifications(cls, commentid):
notifications = []
try:
sql = """select idnumber, axisnumber, notificationid, notificationuserid, notification , notificationtype, userid, notificationusertype, created_at, createdby, requesttype, requestid, foirequestid from (
select frn.idnumber, frn.axisnumber, frn.requestid, frn.notificationid, frns.notificationuserid, frn.notification -> 'message' as notification , nty.name as notificationtype, frn.created_at , frns.createdby, frns.userid, ntu.name as notificationusertype, 'ministryrequest' requesttype, frn.foirequestid from "FOIRequestNotifications" frn inner join "FOIRequestNotificationUsers" frns on frn.notificationid = frns.notificationid and frns.isdeleted = false inner join "NotificationTypes" nty on frn.notificationtypelabel = nty.notificationtypelabel inner join "NotificationUserTypes" ntu on frns.notificationusertypelabel = ntu.notificationusertypelabel where frn.notificationtypelabel in (:notificationtypelabel) and (frn.notification ->> 'commentid')::int = :commentid
select frn.idnumber, frn.axisnumber, frn.requestid, frn.notificationid, frns.notificationuserid, frn.notification -> 'message' as notification , nty.name as notificationtype, frn.created_at , frns.createdby, frns.userid, ntu.name as notificationusertype, 'ministryrequest' requesttype, frn.foirequestid from "FOIRequestNotifications" frn inner join "FOIRequestNotificationUsers" frns on frn.notificationid = frns.notificationid and frns.isdeleted = false inner join "NotificationTypes" nty on frn.notificationtypelabel = nty.notificationtypelabel inner join "NotificationUserTypes" ntu on frns.notificationusertypelabel = ntu.notificationusertypelabel where frn.notificationtypelabel in :notificationtypelabel and (frn.notification ->> 'commentid')::int = :commentid
union all
select frn.idnumber, frn.axisnumber, frn.requestid, frn.notificationid, frns.notificationuserid, frn.notification -> 'message' as notification, nty.name as notificationtype, frn.created_at , frns.createdby, frns.userid, ntu.name as notificationusertype, 'rawrequest' requesttype, 0 foirequestid from "FOIRawRequestNotifications" frn inner join "FOIRawRequestNotificationUsers" frns on frn.notificationid = frns.notificationid and frns.isdeleted = false inner join "NotificationTypes" nty on frn.notificationtypelabel = nty.notificationtypelabel inner join "NotificationUserTypes" ntu on frns.notificationusertypelabel = ntu.notificationusertypelabel where frn.notificationtypelabel in (:notificationtypelabel) and (frn.notification ->> 'commentid')::int = :commentid
select frn.idnumber, frn.axisnumber, frn.requestid, frn.notificationid, frns.notificationuserid, frn.notification -> 'message' as notification, nty.name as notificationtype, frn.created_at , frns.createdby, frns.userid, ntu.name as notificationusertype, 'rawrequest' requesttype, 0 foirequestid from "FOIRawRequestNotifications" frn inner join "FOIRawRequestNotificationUsers" frns on frn.notificationid = frns.notificationid and frns.isdeleted = false inner join "NotificationTypes" nty on frn.notificationtypelabel = nty.notificationtypelabel inner join "NotificationUserTypes" ntu on frns.notificationusertypelabel = ntu.notificationusertypelabel where frn.notificationtypelabel in :notificationtypelabel and (frn.notification ->> 'commentid')::int = :commentid
) as notf order by created_at desc"""
notificationtypelabel = [notificationtypes_cache['newusercomments']['notificationtypelabel'],
notificationtypelabel = tuple([notificationtypes_cache['newusercomments']['notificationtypelabel'],
notificationtypes_cache['replyusercomments']['notificationtypelabel'],
notificationtypes_cache['taggedusercomments']['notificationtypelabel'],
] # 3,9,10
notificationtypelabel = ','.join(str(e) for e in notificationtypelabel)
]) # 3,9,10
# notificationtypelabel = ','.join(str(e) for e in notificationtypelabel)
rs = db.session.execute(text(sql), {'commentid': commentid, 'notificationtypelabel': notificationtypelabel})
for row in rs:
dt = maya.parse(row["created_at"]).datetime(to_timezone='America/Vancouver', naive=False)
Expand Down

0 comments on commit 3722c05

Please sign in to comment.