From 0086bb3e52cf70dc36057ca185fc12c139ec54f9 Mon Sep 17 00:00:00 2001 From: Maereg Sorri Date: Thu, 12 Jan 2023 12:09:33 -0500 Subject: [PATCH 1/3] changes api urls --- .../list/services/mechanisms.service.tsx | 74 +++++++++---------- 1 file changed, 35 insertions(+), 39 deletions(-) diff --git a/src/modules/list/services/mechanisms.service.tsx b/src/modules/list/services/mechanisms.service.tsx index 5ecf0b3..ea78589 100644 --- a/src/modules/list/services/mechanisms.service.tsx +++ b/src/modules/list/services/mechanisms.service.tsx @@ -12,14 +12,15 @@ const agencyGroupSet = 'bw8KHXzxd9i'; const partnerGroupSet = 'BOyWrF33hiR'; function generateMechanismsUrl(filters){ - return `/dataApprovals/categoryOptionCombos?wf=${filters.workflow}&pe=${filters.period}&ou=${filters.ou}`; + return `/dataApprovals/categoryOptionCombos?wf=${filters.workflow}&pe=${filters.period}`; } -function getMechanismInfoUrl(ids){ +function getMechanismInfoUrl(filters){ let filter; - if (ids.length < 500) filter = `filter=categoryOptionCombos.id:in:[${ids.join(',')}]`; - else filter = 'filter=categories.id:eq:SH885jaRe0o'; let fields = 'fields=id,name,organisationUnits[id,name],categoryOptionGroups[id,name,groupSets[id]],categoryOptionCombos[id,name]'; + + if(filters.ou === 'ybg3MO3hcf4') return `/categoryOptions.json?paging=false&${fields}`; + else filter = `filter=organisationUnits.id:eq:${filters.ou}`; return `/categoryOptions.json?paging=false&${filter}&${fields}`; } @@ -63,40 +64,35 @@ function filterSystemMechs(isSuperUser:boolean){ export async function fetchMechanisms(filters:SearchFilters):Promise{ let isSuperUser:boolean = await checkSuperUser(); - return getData(generateMechanismsUrl(filters)).then(mechResp=>{ - // console.log(mechResp, mechResp) - if (mechResp.httpStatusCode===409) return []; - let mechanismIds = mechResp.map(m=>m.id); - return getData(getMechanismInfoUrl(mechanismIds)).then(categoryOptionsResp=>{ - let mechanisms:MechanismModel[] = mechResp.map(mech=>{ - let mechInfo = categoryOptionsResp.categoryOptions.filter(i=>i.categoryOptionCombos[0].id===mech.id)[0]; - if (categoryOptionsResp.categoryOptions.filter(i=>i.id===mech.id).length>1) console.log(`Two info records per mechanism ${mech.id} ${mechInfo.name}`); - let localOU = getOu(mech, mechInfo, isSuperUser); - let status = getStatus(getWorkflowTypeById(filters.workflow), mech.level.level, mech.accepted); - return { - info: { - name: mechInfo.name, - ou: localOU.name||'N/A', - partner: getInfoByGroupSet(mechInfo, partnerGroupSet), - agency: getInfoByGroupSet(mechInfo, agencyGroupSet), - }, - state: { - status: status, - actions: getPermittedActions(mech.permissions, status), - view: mech.permissions.mayReadData - }, - meta: { - cocId: mech.id, - ou: mech.ou, - coId: mechInfo.id - } - }; - }).filter(mech=>mech).filter(filterSystemMechs(isSuperUser)) - return tranformMechanisms(mechanisms); - }).catch(e=>{ - console.error(e); - return []; - }) - }).catch(e=>{return []}); + let getMechData = await getData(generateMechanismsUrl(filters)) + let getMechinfoData = await getData(getMechanismInfoUrl(filters)) + if (getMechData.httpStatusCode===409) return []; + let mechanisms:MechanismModel[] = await getMechData.map(mech=>{ + let mechInfo = getMechinfoData.categoryOptions.filter(i=>i.categoryOptionCombos[0].id===mech.id)[0]; + if (getMechinfoData.categoryOptions.filter(i=>i.id===mech.id).length>1) console.log(`Two info records per mechanism ${mech.id} ${mechInfo.name}`); + if (mechInfo){ + let localOU = getOu(mech, mechInfo, isSuperUser); + let status = getStatus(getWorkflowTypeById(filters.workflow), mech.level.level, mech.accepted); + return { + info: { + name: mechInfo.name, + ou: localOU.name||'N/A', + partner: getInfoByGroupSet(mechInfo, partnerGroupSet), + agency: getInfoByGroupSet(mechInfo, agencyGroupSet), + }, + state: { + status: status, + actions: getPermittedActions(mech.permissions, status), + view: mech.permissions.mayReadData + }, + meta: { + cocId: mech.id, + ou: mech.ou, + coId: mechInfo.id + } + }; + } + }).filter(mech=>mech).filter(filterSystemMechs(isSuperUser)) + return tranformMechanisms(mechanisms); } \ No newline at end of file From 0f70a95268ba44ab495d1305a7b4febe760e3acc Mon Sep 17 00:00:00 2001 From: Maereg Sorri Date: Mon, 30 Jan 2023 22:33:30 -0500 Subject: [PATCH 2/3] clean ups and modifications to filters --- .../list/components/list.component.tsx | 1 - .../list/services/mechanisms.service.tsx | 42 ++++++++++++++++--- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/modules/list/components/list.component.tsx b/src/modules/list/components/list.component.tsx index b428b7e..601123e 100644 --- a/src/modules/list/components/list.component.tsx +++ b/src/modules/list/components/list.component.tsx @@ -102,7 +102,6 @@ export default class List extends React.Component<{ if (!f.ou || !f.period || !f.workflow) return; this.setState({mechanisms: null, loading: {mechanisms: true}}); fetchMechanisms(this.state.filters).then(mechanisms=>{ - console.log(mechanisms) this.setState({mechanisms, loading:{mechanisms: false}}); }).catch((e)=>{ console.error(e); diff --git a/src/modules/list/services/mechanisms.service.tsx b/src/modules/list/services/mechanisms.service.tsx index ea78589..a350698 100644 --- a/src/modules/list/services/mechanisms.service.tsx +++ b/src/modules/list/services/mechanisms.service.tsx @@ -15,12 +15,20 @@ function generateMechanismsUrl(filters){ return `/dataApprovals/categoryOptionCombos?wf=${filters.workflow}&pe=${filters.period}`; } -function getMechanismInfoUrl(filters){ +function getMechanismInfoUrl(filters, isSuperUser){ + let filter; let fields = 'fields=id,name,organisationUnits[id,name],categoryOptionGroups[id,name,groupSets[id]],categoryOptionCombos[id,name]'; - if(filters.ou === 'ybg3MO3hcf4') return `/categoryOptions.json?paging=false&${fields}`; - else filter = `filter=organisationUnits.id:eq:${filters.ou}`; + else + { + + if(isSuperUser){ + filter = `filter=id:in:[xEzelmtHWPn,OM58NubPbx1,mXjFJEexCHJ,t6dWOH7W5Ml]&filter=organisationUnits.id:eq:${filters.ou}&rootJunction=OR`; + } + else + filter = `filter=organisationUnits.id:eq:${filters.ou}`; + } return `/categoryOptions.json?paging=false&${filter}&${fields}`; } @@ -62,13 +70,36 @@ function filterSystemMechs(isSuperUser:boolean){ } } + +function filterOUbased(mechi, mech, orgUnit, isSuperUser){ + let exists = false + if (isSuperUser && orgUnit !== 'ybg3MO3hcf4'){ + if (mechi.organisationUnits.length !== 0){ + if( mechi.categoryOptionCombos[0].id === mech.id && mechi.organisationUnits[0].id === mech.ou){ + exists = true + } + } + else { + if (mechi.categoryOptionCombos[0].id === mech.id){ + if(orgUnit === mech.ou ){ + exists = true + } + } + } + } + else { + if(mechi.categoryOptionCombos[0].id===mech.id) exists = true + } + return exists + } + export async function fetchMechanisms(filters:SearchFilters):Promise{ let isSuperUser:boolean = await checkSuperUser(); let getMechData = await getData(generateMechanismsUrl(filters)) - let getMechinfoData = await getData(getMechanismInfoUrl(filters)) + let getMechinfoData = await getData(getMechanismInfoUrl(filters,isSuperUser)) if (getMechData.httpStatusCode===409) return []; let mechanisms:MechanismModel[] = await getMechData.map(mech=>{ - let mechInfo = getMechinfoData.categoryOptions.filter(i=>i.categoryOptionCombos[0].id===mech.id)[0]; + let mechInfo = getMechinfoData.categoryOptions.filter(i=>filterOUbased(i,mech,filters.ou,isSuperUser))[0] if (getMechinfoData.categoryOptions.filter(i=>i.id===mech.id).length>1) console.log(`Two info records per mechanism ${mech.id} ${mechInfo.name}`); if (mechInfo){ let localOU = getOu(mech, mechInfo, isSuperUser); @@ -94,5 +125,4 @@ export async function fetchMechanisms(filters:SearchFilters):Promisemech).filter(filterSystemMechs(isSuperUser)) return tranformMechanisms(mechanisms); - } \ No newline at end of file From d65d3e1adbf27ee096c764d41a026cd4ef7f344e Mon Sep 17 00:00:00 2001 From: Maereg Sorri Date: Mon, 30 Jan 2023 22:44:42 -0500 Subject: [PATCH 3/3] upgrades app version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 100bae7..56f1cf5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "datim-approvals", - "version": "2.2.0", + "version": "2.2.1", "private": true, "dependencies": { "@dhis2/app-runtime": "^3.2.7",