From e6fa37beb4244d8c5115173af9f3cfbe963c4d1b Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Tue, 10 Jan 2023 16:42:23 +0530 Subject: [PATCH 01/15] ED-94 added block level filter --- .env.sample | 2 + common/druid_queries.json | 8 ++- common/enum.utils.js | 11 +++ controllers/v1/resource.js | 116 ++++++++++++++++++++++++++++++ helper/resource.js | 140 +++++++++++++++++++++++++++++++++++++ 5 files changed, 276 insertions(+), 1 deletion(-) create mode 100644 common/enum.utils.js create mode 100644 controllers/v1/resource.js create mode 100644 helper/resource.js diff --git a/.env.sample b/.env.sample index d2b21c9..ae54fc5 100644 --- a/.env.sample +++ b/.env.sample @@ -10,6 +10,8 @@ OBSERVATION_DATASOURCE_NAME = "OBSERVATION_DATASOURCE_NAME" // Obs OBSERVATION_EVIDENCE_DATASOURCE_NAME = "EVIDENCE_DATASOURCE_NAME" // Observation evidences data source name SURVEY_DATASOURCE_NAME = "SURVEY_DATASOURCE_NAME" // Survey data source name SURVEY_EVIDENCE_DATASOURCE_NAME = "SURVEY_EVIDENCE_DATASOURCE_NAME" // Survey evidence data source name +SOLUTION_RESOURCE_DATASOURCE_NAME = "SOLUTION_RESOURCE_DATASOURCE_NAME" // Solution resource data source name +PROGRAM_RESOURCE_DATASOURCE_NAME = "PROGRAM_RESOURCE_DATASOURCE_NAME" // Program resource data source name CONTENT_REPORT_THRESHOLD = 5 // Restrict number of records to be shown for container reports ENTITY_SCORE_REPORT_THRESHOLD = 5 // Restrict number of submission for entity score report OBSERVATION_SCORE_REPORT_THRESHOLD = 2 // Restrict number of submission per entity in observation report diff --git a/common/druid_queries.json b/common/druid_queries.json index 42be5b3..4387dc3 100644 --- a/common/druid_queries.json +++ b/common/druid_queries.json @@ -73,5 +73,11 @@ "observations_by_entity" : {"queryType":"groupBy","dataSource":"ml_observation_dev","granularity":"all","dimensions":["entityId","entityName","observationName","observationSubmissionId","createdAt"],"filter":{"type":"or","fields":[]},"aggregations":[],"postAggregations":[],"intervals":["1901-01-01T00:00:00+00:00/2101-01-01T00:00:00+00:00"]}, - "question_response_query" : {"queryType":"scan","dataSource":"sl-observation","resultFormat": "list","columns":[ "solutionName", "criteriaName", "domainName", "questionName", "programName", "questionResponseLabel", "observationSubmissionId", "questionResponseType", "questionId", "questionSequenceByEcm","solution_type"],"filter": {"type":"and","fields": [ { "type": "or", "fields": [ { "type": "selector", "dimension": "questionResponseType", "value": "radio" }, { "type": "selector", "dimension": "questionResponseType", "value": "multiselect" }, { "type": "selector", "dimension": "questionResponseType", "value": "slider" } ] } ] },"intervals":"1901-01-01T00:00:00+00:00/2101-01-01T00:00:00+00:00"} + "question_response_query" : {"queryType":"scan","dataSource":"sl-observation","resultFormat": "list","columns":[ "solutionName", "criteriaName", "domainName", "questionName", "programName", "questionResponseLabel", "observationSubmissionId", "questionResponseType", "questionId", "questionSequenceByEcm","solution_type"],"filter": {"type":"and","fields": [ { "type": "or", "fields": [ { "type": "selector", "dimension": "questionResponseType", "value": "radio" }, { "type": "selector", "dimension": "questionResponseType", "value": "multiselect" }, { "type": "selector", "dimension": "questionResponseType", "value": "slider" } ] } ] },"intervals":"1901-01-01T00:00:00+00:00/2101-01-01T00:00:00+00:00"}, + + "distric_level_query": {"queryType": "groupBy","dataSource": "ml-project-status","dimensions": ["district_name", "district_externalId"],"granularity": "all","intervals": "1901-01-01T00:00:00+00:00/2101-01-01T00:00:00+00:00","filter": {"type": "and","fields": []}}, + + "organisations_level_query": {"queryType": "groupBy","dataSource": "ml-project-status","dimensions": ["organisation_id", "organisation_name"],"granularity": "all","intervals": "1901-01-01T00:00:00+00:00/2101-01-01T00:00:00+00:00","filter": {"type": "and","fields": []}}, + + "block_level_query": {"queryType": "groupBy","dataSource": "ml-project-status","dimensions": ["block_externalId", "block_name"],"granularity": "all","intervals": "1901-01-01T00:00:00+00:00/2101-01-01T00:00:00+00:00","filter": {"type": "and","fields": []}} } \ No newline at end of file diff --git a/common/enum.utils.js b/common/enum.utils.js new file mode 100644 index 0000000..0fb3791 --- /dev/null +++ b/common/enum.utils.js @@ -0,0 +1,11 @@ +exports.ResourceTypeProjection = { + DISTRICT:"district", + BLOCK:"block", + ORGANISATION:"organisation" + +} + +exports.ResourceType = { + PROGRAM:"program", + SOLUTION:"solution" +} \ No newline at end of file diff --git a/controllers/v1/resource.js b/controllers/v1/resource.js new file mode 100644 index 0000000..8fbd1ba --- /dev/null +++ b/controllers/v1/resource.js @@ -0,0 +1,116 @@ +const resourceHelper = require("../../helper/resource") +const {ResourceType, ResourceTypeProjection} = require("../../common/enum.utils") + + /** + * @api {post} /mlreports/api/v1/resource/filtervalues?resourceType=program&resourceId=6013eab15faeea0e88a26ef5 + * List of data based on collection + * @apiVersion 1.0.0 + * @apiGroup public + * @apiSampleRequest /mlreports/api/v1/resource/filtervalues + * @param {json} Request-Body: + { + "projection": "block", + "query":{ // optional required for block + "districtLocationId": "b5c35cfc-6c1e-4266-94ef-a425c43c7f4e" + } + } + * @apiParamExample {json} Response: + * { + "message": "Program resource fetched successfully ", + "status": 200, + "result": { + "districts": [ + { + "id": "98ae45d7-9257-4c14-a16a-9760a442ff28", + "name": "PRAKASAM" + }, + { + "id": "0c0391ba-610b-4796-8645-338d047b1e28", + "name": "TIRUVALLUR" + } + ], + "organisations": [ + { + "id": "0126796199493140480", + "name": "Staging Custodian Organization" + } + ] + } + * } + * @apiUse successBody + * @apiUse errorBody + */ + + /** + * List of data based on collection + * @method + * @name filtervalues + * @returns {JSON} list of data. + */ +exports.filtervalues = async function (req, res) { + if(req.query.resourceType == ResourceType.PROGRAM || req.query.resourceType == ResourceType.SOLUTION){ + if(!req.query.resourceId){ + res.status(400).send({ + message: "Resource id not passed" + }) + } + if(req.body.projection == ResourceTypeProjection.DISTRICT){ + const getDistict = await resourceHelper.getDistricts( req ,res) + const getOrganisation = await resourceHelper.getOrganisations(req,res) + if(req.query.resourceType == ResourceType.SOLUTION){ + if(getDistict || getOrganisation){ + const districtOrganisationResponse = { + message: "Solution details fetched successfully", + status: "success", + result:{ + districts: getDistict, + organisations: getOrganisation + } + } + res.status(200).send(districtOrganisationResponse) + } + } else if(req.query.resourceType == ResourceType.PROGRAM){ + if(getDistict || getOrganisation){ + const districtOrganisationResponse = { + message: "Program details fetched successfully", + status: "success", + result:{ + districts: getDistict, + organisations: getOrganisation + } + } + res.status(200).send(districtOrganisationResponse) + } + } + }else if(req.body.projection == ResourceTypeProjection.BLOCK){ + const getBlock = await resourceHelper.getBlocks( req,res ) + if(req.query.resourceType == ResourceType.SOLUTION){ + if(getBlock){ + const blockResponse = { + message: "Solution details fetched successfully", + status: "success", + result:{ + block: getBlock, + } + } + res.status(200).send(blockResponse) + } + }else if(req.query.resourceType == ResourceType.PROGRAM){ + if(getBlock){ + const blockResponse = { + message: "Program details fetched successfully", + status: "success", + result:{ + block: getBlock, + } + } + res.status(200).send(blockResponse) + } + } + } + }else{ + res.status(400).send({ + message: "No data found" + }) + } +} diff --git a/helper/resource.js b/helper/resource.js new file mode 100644 index 0000000..5807de5 --- /dev/null +++ b/helper/resource.js @@ -0,0 +1,140 @@ +const { ResourceType } = require("../common/enum.utils"); +const rp = require('request-promise'); +exports.getDistricts = async function(req,res){ + return new Promise(async function (resolve, reject) { + try { + let bodyParam = gen.utils.getDruidQuery("distric_level_query"); + if(req.query.resourceType == ResourceType.SOLUTION) { + if (process.env.SOLUTION_RESOURCE_DATASOURCE_NAME) { + bodyParam.dataSource = process.env.SOLUTION_RESOURCE_DATASOURCE_NAME; + } + const solutionFilter = { + type: "selector", + dimension: "solution_id", + value: req.query.resourceId + } + bodyParam.filter.fields.push(solutionFilter) + } else if(req.query.resourceType == ResourceType.PROGRAM) { + if (process.env.PROGRAM_RESOURCE_DATASOURCE_NAME) { + bodyParam.dataSource = process.env.PROGRAM_RESOURCE_DATASOURCE_NAME; + } + const programFilter = { + type: "selector", + dimension: "program_id", + value: req.query.resourceId + } + bodyParam.filter.fields.push(programFilter) + } + let options = gen.utils.getDruidConnection(); + options.method = "POST"; + options.body = bodyParam; + console.log({druidConnection: options}); + let data = await rp(options); + if(data){ + const result = data.map(district => ({ id: district.event.district_externalId, name: district.event.district_name })); + resolve(result) + } + }catch(err){ + res.status(400).send({ + result: false, + message: 'INTERNAL_SERVER_ERROR'} + ); + } + }) +} + +exports.getOrganisations = async function(req,res){ + return new Promise(async function (resolve, reject) { + try { + let bodyParam = gen.utils.getDruidQuery("organisations_level_query"); + if(req.query.resourceType == ResourceType.SOLUTION) { + if (process.env.SOLUTION_RESOURCE_DATASOURCE_NAME) { + bodyParam.dataSource = process.env.SOLUTION_RESOURCE_DATASOURCE_NAME; + } + const solutionFilter = { + type: "selector", + dimension: "solution_id", + value: req.query.resourceId + } + bodyParam.filter.fields.push(solutionFilter) + } else if(req.query.resourceType == ResourceType.PROGRAM) { + if (process.env.PROGRAM_RESOURCE_DATASOURCE_NAME) { + bodyParam.dataSource = process.env.PROGRAM_RESOURCE_DATASOURCE_NAME; + } + const programFilter = { + type: "selector", + dimension: "program_id", + value: req.query.resourceId + } + bodyParam.filter.fields.push(programFilter) + } + let options = gen.utils.getDruidConnection(); + options.method = "POST"; + options.body = bodyParam; + console.log({druidConnection: options}); + let data = await rp(options); + if(data){ + const result = data.map(district => ({ id: district.event.organisation_id, name: district.event.organisation_name })); + resolve(result) + } + }catch(err){ + res.status(400).send({ + result: false, + message: 'INTERNAL_SERVER_ERROR'} + ); + } + }) + +} + +exports.getBlocks = async function(req,res){ + return new Promise(async function (resolve, reject) { + try { + let bodyParam = gen.utils.getDruidQuery("block_level_query"); + if(req.query.resourceType == ResourceType.SOLUTION) { + if (process.env.SOLUTION_RESOURCE_DATASOURCE_NAME) { + bodyParam.dataSource = process.env.SOLUTION_RESOURCE_DATASOURCE_NAME; + } + const solutionFilter = { + type: "selector", + dimension: "solution_id", + value: req.query.resourceId + } + bodyParam.filter.fields.push(solutionFilter) + }else if(req.query.resourceType == ResourceType.PROGRAM) { + if (process.env.PROGRAM_RESOURCE_DATASOURCE_NAME) { + bodyParam.dataSource = process.env.PROGRAM_RESOURCE_DATASOURCE_NAME; + } + const programFilter = { + type: "selector", + dimension: "program_id", + value: req.query.resourceId + } + bodyParam.filter.fields.push(programFilter) + } + + const districtFilter = { + type: "selector", + dimension: "district_externalId", + value: req.body.query.districtLocationId + } + bodyParam.filter.fields.push(districtFilter) + let options = gen.utils.getDruidConnection(); + options.method = "POST"; + options.body = bodyParam; + console.log({druidConnection: options}); + let data = await rp(options); + if(data){ + const result = data.map(block => ({ id: block.event.block_externalId, name: block.event.block_name })); + resolve(result) + } + }catch(err){ + res.status(400).send({ + result: false, + message: 'INTERNAL_SERVER_ERROR'} + ); + } + + }) + +} From 04ee814057526f073c4deb3bc06248bde492dbf4 Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Thu, 12 Jan 2023 12:15:27 +0530 Subject: [PATCH 02/15] added varibale in envvaribale file --- envVariables.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/envVariables.js b/envVariables.js index 9afb095..450b5ae 100644 --- a/envVariables.js +++ b/envVariables.js @@ -38,6 +38,14 @@ let enviromentVariables = { "message" : "Required", "optional" : false }, + "SOLUTION_RESOURCE_DATASOURCE_NAME" : { + "message" : "Required", + "optional" : false + }, + "PROGRAM_RESOURCE_DATASOURCE_NAME" : { + "message" : "Required", + "optional" : false + }, "ENTITY_SCORE_REPORT_THRESHOLD" : { "message" : "Required", "optional" : false From 836535b67a939a294916f28a22e2915abfd12182 Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Wed, 1 Feb 2023 08:48:03 +0530 Subject: [PATCH 03/15] Optimized code --- controllers/v1/resource.js | 59 ++++++++------------------- helper/resource.js | 81 +++++++++----------------------------- package.json | 2 +- 3 files changed, 35 insertions(+), 107 deletions(-) diff --git a/controllers/v1/resource.js b/controllers/v1/resource.js index 8fbd1ba..514f7be 100644 --- a/controllers/v1/resource.js +++ b/controllers/v1/resource.js @@ -57,55 +57,28 @@ exports.filtervalues = async function (req, res) { if(req.body.projection == ResourceTypeProjection.DISTRICT){ const getDistict = await resourceHelper.getDistricts( req ,res) const getOrganisation = await resourceHelper.getOrganisations(req,res) - if(req.query.resourceType == ResourceType.SOLUTION){ - if(getDistict || getOrganisation){ - const districtOrganisationResponse = { - message: "Solution details fetched successfully", - status: "success", - result:{ - districts: getDistict, - organisations: getOrganisation - } + if(getDistict || getOrganisation){ + const districtOrganisationResponse = { + message: req.query.resourceType == ResourceType.SOLUTION? "Solution details fetched successfully":"Program details fetched successfully", + status: "success", + result:{ + districts: getDistict, + organisations: getOrganisation } - res.status(200).send(districtOrganisationResponse) - } - } else if(req.query.resourceType == ResourceType.PROGRAM){ - if(getDistict || getOrganisation){ - const districtOrganisationResponse = { - message: "Program details fetched successfully", - status: "success", - result:{ - districts: getDistict, - organisations: getOrganisation - } - } - res.status(200).send(districtOrganisationResponse) } + res.status(200).send(districtOrganisationResponse) } - }else if(req.body.projection == ResourceTypeProjection.BLOCK){ + } else if(req.body.projection == ResourceTypeProjection.BLOCK){ const getBlock = await resourceHelper.getBlocks( req,res ) - if(req.query.resourceType == ResourceType.SOLUTION){ - if(getBlock){ - const blockResponse = { - message: "Solution details fetched successfully", - status: "success", - result:{ - block: getBlock, - } - } - res.status(200).send(blockResponse) - } - }else if(req.query.resourceType == ResourceType.PROGRAM){ - if(getBlock){ - const blockResponse = { - message: "Program details fetched successfully", - status: "success", - result:{ - block: getBlock, - } + if(getBlock){ + const blockResponse = { + message: req.query.resourceType == ResourceType.SOLUTION? "Solution details fetched successfully":"Program details fetched successfully", + status: "success", + result:{ + block: getBlock, } - res.status(200).send(blockResponse) } + res.status(200).send(blockResponse) } } }else{ diff --git a/helper/resource.js b/helper/resource.js index 5807de5..9ddf6d3 100644 --- a/helper/resource.js +++ b/helper/resource.js @@ -4,31 +4,16 @@ exports.getDistricts = async function(req,res){ return new Promise(async function (resolve, reject) { try { let bodyParam = gen.utils.getDruidQuery("distric_level_query"); - if(req.query.resourceType == ResourceType.SOLUTION) { - if (process.env.SOLUTION_RESOURCE_DATASOURCE_NAME) { - bodyParam.dataSource = process.env.SOLUTION_RESOURCE_DATASOURCE_NAME; - } - const solutionFilter = { - type: "selector", - dimension: "solution_id", - value: req.query.resourceId - } - bodyParam.filter.fields.push(solutionFilter) - } else if(req.query.resourceType == ResourceType.PROGRAM) { - if (process.env.PROGRAM_RESOURCE_DATASOURCE_NAME) { - bodyParam.dataSource = process.env.PROGRAM_RESOURCE_DATASOURCE_NAME; - } - const programFilter = { - type: "selector", - dimension: "program_id", - value: req.query.resourceId - } - bodyParam.filter.fields.push(programFilter) + bodyParam.dataSource = req.query.resourceType === ResourceType.SOLUTION ? process.env.SOLUTION_RESOURCE_DATASOURCE_NAME : process.env.PROGRAM_RESOURCE_DATASOURCE_NAME + const resourceFilter = { + type: "selector", + dimension: req.query.resourceType == ResourceType.SOLUTION ? "solution_id" : "program_id", + value: req.query.resourceId } + bodyParam.filter.fields.push(resourceFilter) let options = gen.utils.getDruidConnection(); options.method = "POST"; options.body = bodyParam; - console.log({druidConnection: options}); let data = await rp(options); if(data){ const result = data.map(district => ({ id: district.event.district_externalId, name: district.event.district_name })); @@ -47,31 +32,16 @@ exports.getOrganisations = async function(req,res){ return new Promise(async function (resolve, reject) { try { let bodyParam = gen.utils.getDruidQuery("organisations_level_query"); - if(req.query.resourceType == ResourceType.SOLUTION) { - if (process.env.SOLUTION_RESOURCE_DATASOURCE_NAME) { - bodyParam.dataSource = process.env.SOLUTION_RESOURCE_DATASOURCE_NAME; - } - const solutionFilter = { - type: "selector", - dimension: "solution_id", - value: req.query.resourceId - } - bodyParam.filter.fields.push(solutionFilter) - } else if(req.query.resourceType == ResourceType.PROGRAM) { - if (process.env.PROGRAM_RESOURCE_DATASOURCE_NAME) { - bodyParam.dataSource = process.env.PROGRAM_RESOURCE_DATASOURCE_NAME; - } - const programFilter = { - type: "selector", - dimension: "program_id", - value: req.query.resourceId - } - bodyParam.filter.fields.push(programFilter) + bodyParam.dataSource = req.query.resourceType === ResourceType.SOLUTION ? process.env.SOLUTION_RESOURCE_DATASOURCE_NAME : process.env.PROGRAM_RESOURCE_DATASOURCE_NAME + const resourceFilter = { + type: "selector", + dimension: req.query.resourceType == ResourceType.SOLUTION ? "solution_id" : "program_id", + value: req.query.resourceId } + bodyParam.filter.fields.push(resourceFilter) let options = gen.utils.getDruidConnection(); options.method = "POST"; options.body = bodyParam; - console.log({druidConnection: options}); let data = await rp(options); if(data){ const result = data.map(district => ({ id: district.event.organisation_id, name: district.event.organisation_name })); @@ -91,27 +61,13 @@ exports.getBlocks = async function(req,res){ return new Promise(async function (resolve, reject) { try { let bodyParam = gen.utils.getDruidQuery("block_level_query"); - if(req.query.resourceType == ResourceType.SOLUTION) { - if (process.env.SOLUTION_RESOURCE_DATASOURCE_NAME) { - bodyParam.dataSource = process.env.SOLUTION_RESOURCE_DATASOURCE_NAME; - } - const solutionFilter = { - type: "selector", - dimension: "solution_id", - value: req.query.resourceId - } - bodyParam.filter.fields.push(solutionFilter) - }else if(req.query.resourceType == ResourceType.PROGRAM) { - if (process.env.PROGRAM_RESOURCE_DATASOURCE_NAME) { - bodyParam.dataSource = process.env.PROGRAM_RESOURCE_DATASOURCE_NAME; - } - const programFilter = { - type: "selector", - dimension: "program_id", - value: req.query.resourceId - } - bodyParam.filter.fields.push(programFilter) + bodyParam.dataSource = req.query.resourceType === ResourceType.SOLUTION ? process.env.SOLUTION_RESOURCE_DATASOURCE_NAME : process.env.PROGRAM_RESOURCE_DATASOURCE_NAME + const resourceFilter = { + type: "selector", + dimension: req.query.resourceType == ResourceType.SOLUTION ? "solution_id" : "program_id", + value: req.query.resourceId } + bodyParam.filter.fields.push(resourceFilter) const districtFilter = { type: "selector", @@ -122,7 +78,6 @@ exports.getBlocks = async function(req,res){ let options = gen.utils.getDruidConnection(); options.method = "POST"; options.body = bodyParam; - console.log({druidConnection: options}); let data = await rp(options); if(data){ const result = data.map(block => ({ id: block.event.block_externalId, name: block.event.block_name })); diff --git a/package.json b/package.json index 77194f0..855a2f3 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "1.0.0", "private": true, "scripts": { - "start": "app.js", + "start": "node app.js", "test": "mocha --timeout 10000", "coverage": " nyc --reporter=lcov mocha --timeout 10000 test --exit" }, From a5f4d37f6f54e9cc9b7793b403a7d8633a1a7127 Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Tue, 7 Feb 2023 09:59:08 +0530 Subject: [PATCH 04/15] Added user extension validation --- common/druid_queries.json | 12 +++++-- common/endpoints.js | 3 +- controllers/v1/resource.js | 68 +++++++++++++++++++++----------------- helper/kendra_service.js | 32 +++++++++++++++++- helper/resource.js | 26 ++++++++++++--- 5 files changed, 102 insertions(+), 39 deletions(-) diff --git a/common/druid_queries.json b/common/druid_queries.json index 4387dc3..964e481 100644 --- a/common/druid_queries.json +++ b/common/druid_queries.json @@ -75,9 +75,15 @@ "question_response_query" : {"queryType":"scan","dataSource":"sl-observation","resultFormat": "list","columns":[ "solutionName", "criteriaName", "domainName", "questionName", "programName", "questionResponseLabel", "observationSubmissionId", "questionResponseType", "questionId", "questionSequenceByEcm","solution_type"],"filter": {"type":"and","fields": [ { "type": "or", "fields": [ { "type": "selector", "dimension": "questionResponseType", "value": "radio" }, { "type": "selector", "dimension": "questionResponseType", "value": "multiselect" }, { "type": "selector", "dimension": "questionResponseType", "value": "slider" } ] } ] },"intervals":"1901-01-01T00:00:00+00:00/2101-01-01T00:00:00+00:00"}, - "distric_level_query": {"queryType": "groupBy","dataSource": "ml-project-status","dimensions": ["district_name", "district_externalId"],"granularity": "all","intervals": "1901-01-01T00:00:00+00:00/2101-01-01T00:00:00+00:00","filter": {"type": "and","fields": []}}, + "solution_distric_level_query": {"queryType": "groupBy","dataSource": "ml-project-status","dimensions": ["district_name", "district_externalId"],"granularity": "all","intervals": "1901-01-01T00:00:00+00:00/2101-01-01T00:00:00+00:00","filter": {"type": "and","fields": []}}, - "organisations_level_query": {"queryType": "groupBy","dataSource": "ml-project-status","dimensions": ["organisation_id", "organisation_name"],"granularity": "all","intervals": "1901-01-01T00:00:00+00:00/2101-01-01T00:00:00+00:00","filter": {"type": "and","fields": []}}, + "solution_organisations_level_query": {"queryType": "groupBy","dataSource": "ml-project-status","dimensions": ["organisation_id", "organisation_name"],"granularity": "all","intervals": "1901-01-01T00:00:00+00:00/2101-01-01T00:00:00+00:00","filter": {"type": "and","fields": []}}, - "block_level_query": {"queryType": "groupBy","dataSource": "ml-project-status","dimensions": ["block_externalId", "block_name"],"granularity": "all","intervals": "1901-01-01T00:00:00+00:00/2101-01-01T00:00:00+00:00","filter": {"type": "and","fields": []}} + "solution_block_level_query": {"queryType": "groupBy","dataSource": "ml-project-status","dimensions": ["block_externalId", "block_name"],"granularity": "all","intervals": "1901-01-01T00:00:00+00:00/2101-01-01T00:00:00+00:00","filter": {"type": "and","fields": []}}, + + "program_distric_level_query": {"queryType": "groupBy","dataSource": "ml-programusers-status","dimensions": ["district_name", "district_id"],"granularity": "all","intervals": "1901-01-01T00:00:00+00:00/2101-01-01T00:00:00+00:00","filter": {"type": "and","fields": []}}, + + "program_organisations_level_query": {"queryType": "groupBy","dataSource": "ml-programusers-status","dimensions": ["organisation_id", "organisation_name"],"granularity": "all","intervals": "1901-01-01T00:00:00+00:00/2101-01-01T00:00:00+00:00","filter": {"type": "and","fields": []}}, + + "program_block_level_query": {"queryType": "groupBy","dataSource": "ml-programusers-status","dimensions": ["block_id", "block_name"],"granularity": "all","intervals": "1901-01-01T00:00:00+00:00/2101-01-01T00:00:00+00:00","filter": {"type": "and","fields": []}} } \ No newline at end of file diff --git a/common/endpoints.js b/common/endpoints.js index 437bdab..76c1d2e 100644 --- a/common/endpoints.js +++ b/common/endpoints.js @@ -16,5 +16,6 @@ module.exports = { AZURE_GET_DOWNLOADABLE_URL : "/v1/cloud-services/azure/getDownloadableUrl", AWS_GET_DOWNLOADABLE_URL : "/v1/cloud-services/aws/getDownloadableUrl", GET_PRESIGNED_URL : "/v1/cloud-services/files/preSignedUrls", - GET_DOWNLOADABLE_URL: "/v1/cloud-services/files/getDownloadableUrl" + GET_DOWNLOADABLE_URL: "/v1/cloud-services/files/getDownloadableUrl", + GET_USER_EXTENSION : "/v1/user-extension/read" } \ No newline at end of file diff --git a/controllers/v1/resource.js b/controllers/v1/resource.js index 514f7be..7450dde 100644 --- a/controllers/v1/resource.js +++ b/controllers/v1/resource.js @@ -48,42 +48,50 @@ const {ResourceType, ResourceTypeProjection} = require("../../common/enum.utils" * @returns {JSON} list of data. */ exports.filtervalues = async function (req, res) { - if(req.query.resourceType == ResourceType.PROGRAM || req.query.resourceType == ResourceType.SOLUTION){ - if(!req.query.resourceId){ - res.status(400).send({ - message: "Resource id not passed" - }) - } - if(req.body.projection == ResourceTypeProjection.DISTRICT){ - const getDistict = await resourceHelper.getDistricts( req ,res) - const getOrganisation = await resourceHelper.getOrganisations(req,res) - if(getDistict || getOrganisation){ - const districtOrganisationResponse = { - message: req.query.resourceType == ResourceType.SOLUTION? "Solution details fetched successfully":"Program details fetched successfully", - status: "success", - result:{ - districts: getDistict, - organisations: getOrganisation + + const userExtension = await resourceHelper.userExtensions(req,res); + if(userExtension){ + if(req.query.resourceType == ResourceType.PROGRAM || req.query.resourceType == ResourceType.SOLUTION){ + if(!req.query.resourceId){ + res.status(400).send({ + message: "Resource id not passed" + }) + } + if(req.body.projection == ResourceTypeProjection.DISTRICT){ + const getDistict = await resourceHelper.getDistricts( req ,res) + const getOrganisation = await resourceHelper.getOrganisations(req,res) + if(getDistict || getOrganisation){ + const districtOrganisationResponse = { + message: req.query.resourceType == ResourceType.SOLUTION? "Solution details fetched successfully":"Program details fetched successfully", + status: "success", + result:{ + districts: getDistict, + organisations: getOrganisation + } } + res.status(200).send(districtOrganisationResponse) } - res.status(200).send(districtOrganisationResponse) - } - } else if(req.body.projection == ResourceTypeProjection.BLOCK){ - const getBlock = await resourceHelper.getBlocks( req,res ) - if(getBlock){ - const blockResponse = { - message: req.query.resourceType == ResourceType.SOLUTION? "Solution details fetched successfully":"Program details fetched successfully", - status: "success", - result:{ - block: getBlock, + } else if(req.body.projection == ResourceTypeProjection.BLOCK){ + const getBlock = await resourceHelper.getBlocks( req,res ) + if(getBlock){ + const blockResponse = { + message: req.query.resourceType == ResourceType.SOLUTION? "Solution details fetched successfully":"Program details fetched successfully", + status: "success", + result:{ + block: getBlock, + } } + res.status(200).send(blockResponse) } - res.status(200).send(blockResponse) } + }else{ + res.status(400).send({ + message: "No data found" + }) } - }else{ - res.status(400).send({ - message: "No data found" + }else { + res.status(401).send({ + message: "You are not authorised to access this resource" }) } } diff --git a/helper/kendra_service.js b/helper/kendra_service.js index 67d056a..fd09371 100644 --- a/helper/kendra_service.js +++ b/helper/kendra_service.js @@ -66,8 +66,38 @@ async function getPreSignedUrl(file) { }) } +async function getUserExtension(token){ + return new Promise(async function (resolve, reject) { + + let url = urlPrefix + endpoints.GET_USER_EXTENSION; + console.log({ 'CoreServiceUserExtensionUrl: ': url }); + + let options = { + method: "POST", + json: true, + headers: { + "x-authenticated-user-token": token, + "internal-access-token": process.env.INTERNAL_ACCESS_TOKEN, + "Content-Type": "application/json", + }, + body: {}, + uri: url + } + + rp(options) + .then(result => { + return resolve(result); + }) + .catch(err => { + return resolve(err); + }) + }) + +} + module.exports = { getDownloadableUrl: getDownloadableUrl, - getPreSignedUrl: getPreSignedUrl + getPreSignedUrl: getPreSignedUrl, + getUserExtension:getUserExtension } \ No newline at end of file diff --git a/helper/resource.js b/helper/resource.js index 9ddf6d3..a379b32 100644 --- a/helper/resource.js +++ b/helper/resource.js @@ -1,9 +1,27 @@ const { ResourceType } = require("../common/enum.utils"); const rp = require('request-promise'); +const { get } = require("request"); +const kendra_service = require("./kendra_service"); + +exports.userExtensions = async function (req,res){ + return new Promise(async function (resolve, reject) { + try { + let userExtensions = await kendra_service.getUserExtension(req.userDetails.token) + if(userExtensions.status === 200){ + resolve(true); + }else{ + resolve(false); + } + }catch(error){ + console.log(error); + } +})} + + exports.getDistricts = async function(req,res){ return new Promise(async function (resolve, reject) { try { - let bodyParam = gen.utils.getDruidQuery("distric_level_query"); + let bodyParam = req.query.resourceType === ResourceType.SOLUTION ? gen.utils.getDruidQuery("solution_distric_level_query") : get.utils.getDruidQuery("program_distric_level_query"); bodyParam.dataSource = req.query.resourceType === ResourceType.SOLUTION ? process.env.SOLUTION_RESOURCE_DATASOURCE_NAME : process.env.PROGRAM_RESOURCE_DATASOURCE_NAME const resourceFilter = { type: "selector", @@ -31,7 +49,7 @@ exports.getDistricts = async function(req,res){ exports.getOrganisations = async function(req,res){ return new Promise(async function (resolve, reject) { try { - let bodyParam = gen.utils.getDruidQuery("organisations_level_query"); + let bodyParam = req.query.resourceType === ResourceType.SOLUTION ? gen.utils.getDruidQuery("solution_organisations_level_query") : get.utils.getDruidQuery("program_organisations_level_query"); bodyParam.dataSource = req.query.resourceType === ResourceType.SOLUTION ? process.env.SOLUTION_RESOURCE_DATASOURCE_NAME : process.env.PROGRAM_RESOURCE_DATASOURCE_NAME const resourceFilter = { type: "selector", @@ -60,7 +78,7 @@ exports.getOrganisations = async function(req,res){ exports.getBlocks = async function(req,res){ return new Promise(async function (resolve, reject) { try { - let bodyParam = gen.utils.getDruidQuery("block_level_query"); + let bodyParam = req.query.resourceType === ResourceType.SOLUTION ? gen.utils.getDruidQuery("solution_block_level_query") : get.utils.getDruidQuery("program_block_level_query"); bodyParam.dataSource = req.query.resourceType === ResourceType.SOLUTION ? process.env.SOLUTION_RESOURCE_DATASOURCE_NAME : process.env.PROGRAM_RESOURCE_DATASOURCE_NAME const resourceFilter = { type: "selector", @@ -71,7 +89,7 @@ exports.getBlocks = async function(req,res){ const districtFilter = { type: "selector", - dimension: "district_externalId", + dimension: req.query.resourceType == ResourceType.SOLUTION ? "district_externalId" : "district_id", value: req.body.query.districtLocationId } bodyParam.filter.fields.push(districtFilter) From 45f5e63fc8e5a7489e487b0a2eb1e821767d783e Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Tue, 7 Mar 2023 18:00:57 +0530 Subject: [PATCH 05/15] removed console log --- helper/kendra_service.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/helper/kendra_service.js b/helper/kendra_service.js index fd09371..75ec327 100644 --- a/helper/kendra_service.js +++ b/helper/kendra_service.js @@ -70,8 +70,6 @@ async function getUserExtension(token){ return new Promise(async function (resolve, reject) { let url = urlPrefix + endpoints.GET_USER_EXTENSION; - console.log({ 'CoreServiceUserExtensionUrl: ': url }); - let options = { method: "POST", json: true, From bb8b1afa4a7604c805dc94c38014539040fe3816 Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Mon, 10 Apr 2023 14:36:03 +0530 Subject: [PATCH 06/15] Added all data source and All types of solutions --- .env.sample | 4 +++- common/enum.utils.js | 6 ++++++ envVariables.js | 10 +++++++++- helper/resource.js | 43 +++++++++++++++++++++++++++++++------------ 4 files changed, 49 insertions(+), 14 deletions(-) diff --git a/.env.sample b/.env.sample index ae54fc5..ae0ef43 100644 --- a/.env.sample +++ b/.env.sample @@ -10,7 +10,9 @@ OBSERVATION_DATASOURCE_NAME = "OBSERVATION_DATASOURCE_NAME" // Obs OBSERVATION_EVIDENCE_DATASOURCE_NAME = "EVIDENCE_DATASOURCE_NAME" // Observation evidences data source name SURVEY_DATASOURCE_NAME = "SURVEY_DATASOURCE_NAME" // Survey data source name SURVEY_EVIDENCE_DATASOURCE_NAME = "SURVEY_EVIDENCE_DATASOURCE_NAME" // Survey evidence data source name -SOLUTION_RESOURCE_DATASOURCE_NAME = "SOLUTION_RESOURCE_DATASOURCE_NAME" // Solution resource data source name +PROJECT_RESOURCE_DATASOURCE_NAME = "PROJECT_RESOURCE_DATASOURCE_NAME" // Solution resource data source name +OBSERVATION_RESOURCE_DATASOURCE_NAME = "OBSERVATION_RESOURCE_DATASOURCE_NAME" // Solution resource data source name +SURVEY_RESOURCE_DATASOURCE_NAME = "SURVEY_RESOURCE_DATASOURCE_NAME" // Solution resource data source name PROGRAM_RESOURCE_DATASOURCE_NAME = "PROGRAM_RESOURCE_DATASOURCE_NAME" // Program resource data source name CONTENT_REPORT_THRESHOLD = 5 // Restrict number of records to be shown for container reports ENTITY_SCORE_REPORT_THRESHOLD = 5 // Restrict number of submission for entity score report diff --git a/common/enum.utils.js b/common/enum.utils.js index 0fb3791..a07cee4 100644 --- a/common/enum.utils.js +++ b/common/enum.utils.js @@ -8,4 +8,10 @@ exports.ResourceTypeProjection = { exports.ResourceType = { PROGRAM:"program", SOLUTION:"solution" +} + +exports.SolutionType = { + PROJECT : "improvementProject", + OBSERVATION: "observation", + SURVEY :"survey" } \ No newline at end of file diff --git a/envVariables.js b/envVariables.js index 450b5ae..f4abda1 100644 --- a/envVariables.js +++ b/envVariables.js @@ -38,7 +38,15 @@ let enviromentVariables = { "message" : "Required", "optional" : false }, - "SOLUTION_RESOURCE_DATASOURCE_NAME" : { + "PROJECT_RESOURCE_DATASOURCE_NAME" : { + "message" : "Required", + "optional" : false + }, + "OBSERVATION_RESOURCE_DATASOURCE_NAME" : { + "message" : "Required", + "optional" : false + }, + "SURVEY_RESOURCE_DATASOURCE_NAME" : { "message" : "Required", "optional" : false }, diff --git a/helper/resource.js b/helper/resource.js index a379b32..7861a71 100644 --- a/helper/resource.js +++ b/helper/resource.js @@ -1,4 +1,4 @@ -const { ResourceType } = require("../common/enum.utils"); +const { ResourceType, SolutionType } = require("../common/enum.utils"); const rp = require('request-promise'); const { get } = require("request"); const kendra_service = require("./kendra_service"); @@ -7,8 +7,15 @@ exports.userExtensions = async function (req,res){ return new Promise(async function (resolve, reject) { try { let userExtensions = await kendra_service.getUserExtension(req.userDetails.token) + console.log(JSON.stringify(userExtensions)) if(userExtensions.status === 200){ - resolve(true); + for(let platformCode = 0; platformCode < userExtensions.result.platformRoles.length; platformCode++){ + if(userExtensions.result.platformRoles[platformCode].code === "PROGRAM_DESIGNER" || userExtensions.result.platformRoles[platformCode].code === "PROGRAM_MANAGER"){ + resolve(true) + break; + } + } + resolve(false); }else{ resolve(false); } @@ -21,8 +28,12 @@ exports.userExtensions = async function (req,res){ exports.getDistricts = async function(req,res){ return new Promise(async function (resolve, reject) { try { - let bodyParam = req.query.resourceType === ResourceType.SOLUTION ? gen.utils.getDruidQuery("solution_distric_level_query") : get.utils.getDruidQuery("program_distric_level_query"); - bodyParam.dataSource = req.query.resourceType === ResourceType.SOLUTION ? process.env.SOLUTION_RESOURCE_DATASOURCE_NAME : process.env.PROGRAM_RESOURCE_DATASOURCE_NAME + let bodyParam = req.query.resourceType === ResourceType.SOLUTION ? gen.utils.getDruidQuery("solution_distric_level_query") : gen.utils.getDruidQuery("program_distric_level_query"); + if(req.query.resourceType === ResourceType.PROGRAM){ + bodyParam.dataSource = process.env.PROGRAM_RESOURCE_DATASOURCE_NAME + }else { + bodyParam.dataSource = req.body.solutionType === SolutionType.PROJECT ? process.env.PROJECT_RESOURCE_DATASOURCE_NAME : req.body.solutionType === SolutionType.OBSERVATION ? process.env.OBSERVATION_RESOURCE_DATASOURCE_NAME : process.env.SURVEY_RESOURCE_DATASOURCE_NAME + } const resourceFilter = { type: "selector", dimension: req.query.resourceType == ResourceType.SOLUTION ? "solution_id" : "program_id", @@ -34,14 +45,14 @@ exports.getDistricts = async function(req,res){ options.body = bodyParam; let data = await rp(options); if(data){ - const result = data.map(district => ({ id: district.event.district_externalId, name: district.event.district_name })); + const result = data.map(district => ({ id: req.query.resourceType == ResourceType.SOLUTION ? district.event.district_externalId : district.event.district_id, name: district.event.district_name })); resolve(result) } }catch(err){ res.status(400).send({ result: false, - message: 'INTERNAL_SERVER_ERROR'} - ); + message: 'INTERNAL_SERVER_ERROR' + }); } }) } @@ -49,8 +60,12 @@ exports.getDistricts = async function(req,res){ exports.getOrganisations = async function(req,res){ return new Promise(async function (resolve, reject) { try { - let bodyParam = req.query.resourceType === ResourceType.SOLUTION ? gen.utils.getDruidQuery("solution_organisations_level_query") : get.utils.getDruidQuery("program_organisations_level_query"); - bodyParam.dataSource = req.query.resourceType === ResourceType.SOLUTION ? process.env.SOLUTION_RESOURCE_DATASOURCE_NAME : process.env.PROGRAM_RESOURCE_DATASOURCE_NAME + let bodyParam = req.query.resourceType === ResourceType.SOLUTION ? gen.utils.getDruidQuery("solution_organisations_level_query") : gen.utils.getDruidQuery("program_organisations_level_query"); + if(req.query.resourceType === ResourceType.PROGRAM){ + bodyParam.dataSource = process.env.PROGRAM_RESOURCE_DATASOURCE_NAME + }else { + bodyParam.dataSource = req.body.solutionType === SolutionType.PROJECT ? process.env.PROJECT_RESOURCE_DATASOURCE_NAME : req.body.solutionType === SolutionType.OBSERVATION ? process.env.OBSERVATION_RESOURCE_DATASOURCE_NAME : process.env.SURVEY_RESOURCE_DATASOURCE_NAME + } const resourceFilter = { type: "selector", dimension: req.query.resourceType == ResourceType.SOLUTION ? "solution_id" : "program_id", @@ -78,8 +93,12 @@ exports.getOrganisations = async function(req,res){ exports.getBlocks = async function(req,res){ return new Promise(async function (resolve, reject) { try { - let bodyParam = req.query.resourceType === ResourceType.SOLUTION ? gen.utils.getDruidQuery("solution_block_level_query") : get.utils.getDruidQuery("program_block_level_query"); - bodyParam.dataSource = req.query.resourceType === ResourceType.SOLUTION ? process.env.SOLUTION_RESOURCE_DATASOURCE_NAME : process.env.PROGRAM_RESOURCE_DATASOURCE_NAME + let bodyParam = req.query.resourceType === ResourceType.SOLUTION ? gen.utils.getDruidQuery("solution_block_level_query") : gen.utils.getDruidQuery("program_block_level_query"); + if(req.query.resourceType === ResourceType.PROGRAM){ + bodyParam.dataSource = process.env.PROGRAM_RESOURCE_DATASOURCE_NAME + }else { + bodyParam.dataSource = req.body.solutionType === SolutionType.PROJECT ? process.env.PROJECT_RESOURCE_DATASOURCE_NAME : req.body.solutionType === SolutionType.OBSERVATION ? process.env.OBSERVATION_RESOURCE_DATASOURCE_NAME : process.env.SURVEY_RESOURCE_DATASOURCE_NAME + } const resourceFilter = { type: "selector", dimension: req.query.resourceType == ResourceType.SOLUTION ? "solution_id" : "program_id", @@ -98,7 +117,7 @@ exports.getBlocks = async function(req,res){ options.body = bodyParam; let data = await rp(options); if(data){ - const result = data.map(block => ({ id: block.event.block_externalId, name: block.event.block_name })); + const result = data.map(block => ({ id: req.query.resourceType == ResourceType.SOLUTION ? block.event.block_externalId : block.event.block_id, name: block.event.block_name })); resolve(result) } }catch(err){ From f59d1aa4917f781ca1b9668577b8353603a5da46 Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Mon, 10 Apr 2023 14:43:19 +0530 Subject: [PATCH 07/15] Added all data source and All types of solutions --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 855a2f3..77194f0 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "1.0.0", "private": true, "scripts": { - "start": "node app.js", + "start": "app.js", "test": "mocha --timeout 10000", "coverage": " nyc --reporter=lcov mocha --timeout 10000 test --exit" }, From 028c71ef1657a3fb12eff4f0bbf5ece7c4cbf08e Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Mon, 10 Apr 2023 15:22:01 +0530 Subject: [PATCH 08/15] Added all data source and All types of solutions --- helper/resource.js | 1 - 1 file changed, 1 deletion(-) diff --git a/helper/resource.js b/helper/resource.js index 7861a71..ed7d1a6 100644 --- a/helper/resource.js +++ b/helper/resource.js @@ -7,7 +7,6 @@ exports.userExtensions = async function (req,res){ return new Promise(async function (resolve, reject) { try { let userExtensions = await kendra_service.getUserExtension(req.userDetails.token) - console.log(JSON.stringify(userExtensions)) if(userExtensions.status === 200){ for(let platformCode = 0; platformCode < userExtensions.result.platformRoles.length; platformCode++){ if(userExtensions.result.platformRoles[platformCode].code === "PROGRAM_DESIGNER" || userExtensions.result.platformRoles[platformCode].code === "PROGRAM_MANAGER"){ From 79df440c4a0506fc54e85ec19cebe2b156e8d95d Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Mon, 10 Apr 2023 15:27:56 +0530 Subject: [PATCH 09/15] Added all data source and All types of solutions --- controllers/v1/resource.js | 9 +++++++++ helper/resource.js | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/controllers/v1/resource.js b/controllers/v1/resource.js index 7450dde..e711f65 100644 --- a/controllers/v1/resource.js +++ b/controllers/v1/resource.js @@ -1,3 +1,11 @@ +/** + * name : resource.js + * author : Ankit Shahu + * created-date : 10-April-2023 + * Description : Resource level data for program and solution. + */ + + const resourceHelper = require("../../helper/resource") const {ResourceType, ResourceTypeProjection} = require("../../common/enum.utils") @@ -13,6 +21,7 @@ const {ResourceType, ResourceTypeProjection} = require("../../common/enum.utils" "query":{ // optional required for block "districtLocationId": "b5c35cfc-6c1e-4266-94ef-a425c43c7f4e" } + "solutionType": "observation"/"survey"/"improvementProject" //Required only for resourceType=solution } * @apiParamExample {json} Response: * { diff --git a/helper/resource.js b/helper/resource.js index ed7d1a6..c36811f 100644 --- a/helper/resource.js +++ b/helper/resource.js @@ -1,3 +1,11 @@ +/** + * name : resource.js + * author : Ankit Shahu + * created-date : 10-April-2023 + * Description : Resource level data for program and solution. + */ + + const { ResourceType, SolutionType } = require("../common/enum.utils"); const rp = require('request-promise'); const { get } = require("request"); From e3dc75d5b71fb2d80a552734564478a8a03054e2 Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Mon, 10 Apr 2023 18:51:31 +0530 Subject: [PATCH 10/15] Added Reuseable functions and Resolving all the comments --- .env.sample | 6 ++-- .gitignore | 2 ++ common/druid_queries.json | 12 +++---- common/enum.utils.js | 17 ++++++++++ common/utils.js | 36 +++++++++++++++++++-- controllers/v1/resource.js | 1 + helper/resource.js | 65 ++++++++++++++------------------------ 7 files changed, 87 insertions(+), 52 deletions(-) diff --git a/.env.sample b/.env.sample index ae0ef43..3366327 100644 --- a/.env.sample +++ b/.env.sample @@ -10,9 +10,9 @@ OBSERVATION_DATASOURCE_NAME = "OBSERVATION_DATASOURCE_NAME" // Obs OBSERVATION_EVIDENCE_DATASOURCE_NAME = "EVIDENCE_DATASOURCE_NAME" // Observation evidences data source name SURVEY_DATASOURCE_NAME = "SURVEY_DATASOURCE_NAME" // Survey data source name SURVEY_EVIDENCE_DATASOURCE_NAME = "SURVEY_EVIDENCE_DATASOURCE_NAME" // Survey evidence data source name -PROJECT_RESOURCE_DATASOURCE_NAME = "PROJECT_RESOURCE_DATASOURCE_NAME" // Solution resource data source name -OBSERVATION_RESOURCE_DATASOURCE_NAME = "OBSERVATION_RESOURCE_DATASOURCE_NAME" // Solution resource data source name -SURVEY_RESOURCE_DATASOURCE_NAME = "SURVEY_RESOURCE_DATASOURCE_NAME" // Solution resource data source name +PROJECT_RESOURCE_DATASOURCE_NAME = "PROJECT_RESOURCE_DATASOURCE_NAME" // project resource data source name +OBSERVATION_RESOURCE_DATASOURCE_NAME = "OBSERVATION_RESOURCE_DATASOURCE_NAME" // observation resource data source name +SURVEY_RESOURCE_DATASOURCE_NAME = "SURVEY_RESOURCE_DATASOURCE_NAME" // survey resource data source name PROGRAM_RESOURCE_DATASOURCE_NAME = "PROGRAM_RESOURCE_DATASOURCE_NAME" // Program resource data source name CONTENT_REPORT_THRESHOLD = 5 // Restrict number of records to be shown for container reports ENTITY_SCORE_REPORT_THRESHOLD = 5 // Restrict number of submission for entity score report diff --git a/.gitignore b/.gitignore index ea5939c..c29d7ea 100644 --- a/.gitignore +++ b/.gitignore @@ -64,3 +64,5 @@ typings/ config/config.json tmp/* package-lock.json +keycloak-public-keys/ +.vscode/ diff --git a/common/druid_queries.json b/common/druid_queries.json index 964e481..078698c 100644 --- a/common/druid_queries.json +++ b/common/druid_queries.json @@ -75,15 +75,15 @@ "question_response_query" : {"queryType":"scan","dataSource":"sl-observation","resultFormat": "list","columns":[ "solutionName", "criteriaName", "domainName", "questionName", "programName", "questionResponseLabel", "observationSubmissionId", "questionResponseType", "questionId", "questionSequenceByEcm","solution_type"],"filter": {"type":"and","fields": [ { "type": "or", "fields": [ { "type": "selector", "dimension": "questionResponseType", "value": "radio" }, { "type": "selector", "dimension": "questionResponseType", "value": "multiselect" }, { "type": "selector", "dimension": "questionResponseType", "value": "slider" } ] } ] },"intervals":"1901-01-01T00:00:00+00:00/2101-01-01T00:00:00+00:00"}, - "solution_distric_level_query": {"queryType": "groupBy","dataSource": "ml-project-status","dimensions": ["district_name", "district_externalId"],"granularity": "all","intervals": "1901-01-01T00:00:00+00:00/2101-01-01T00:00:00+00:00","filter": {"type": "and","fields": []}}, + "solution_distric_level_query": {"queryType": "groupBy","dataSource": "","dimensions": ["district_name", "district_externalId"],"granularity": "all","intervals": "1901-01-01T00:00:00+00:00/2101-01-01T00:00:00+00:00","filter": {"type": "and","fields": []}}, - "solution_organisations_level_query": {"queryType": "groupBy","dataSource": "ml-project-status","dimensions": ["organisation_id", "organisation_name"],"granularity": "all","intervals": "1901-01-01T00:00:00+00:00/2101-01-01T00:00:00+00:00","filter": {"type": "and","fields": []}}, + "solution_organisations_level_query": {"queryType": "groupBy","dataSource": "","dimensions": ["organisation_id", "organisation_name"],"granularity": "all","intervals": "1901-01-01T00:00:00+00:00/2101-01-01T00:00:00+00:00","filter": {"type": "and","fields": []}}, - "solution_block_level_query": {"queryType": "groupBy","dataSource": "ml-project-status","dimensions": ["block_externalId", "block_name"],"granularity": "all","intervals": "1901-01-01T00:00:00+00:00/2101-01-01T00:00:00+00:00","filter": {"type": "and","fields": []}}, + "solution_block_level_query": {"queryType": "groupBy","dataSource": "","dimensions": ["block_externalId", "block_name"],"granularity": "all","intervals": "1901-01-01T00:00:00+00:00/2101-01-01T00:00:00+00:00","filter": {"type": "and","fields": []}}, - "program_distric_level_query": {"queryType": "groupBy","dataSource": "ml-programusers-status","dimensions": ["district_name", "district_id"],"granularity": "all","intervals": "1901-01-01T00:00:00+00:00/2101-01-01T00:00:00+00:00","filter": {"type": "and","fields": []}}, + "program_distric_level_query": {"queryType": "groupBy","dataSource": "","dimensions": ["district_name", "district_id"],"granularity": "all","intervals": "1901-01-01T00:00:00+00:00/2101-01-01T00:00:00+00:00","filter": {"type": "and","fields": []}}, - "program_organisations_level_query": {"queryType": "groupBy","dataSource": "ml-programusers-status","dimensions": ["organisation_id", "organisation_name"],"granularity": "all","intervals": "1901-01-01T00:00:00+00:00/2101-01-01T00:00:00+00:00","filter": {"type": "and","fields": []}}, + "program_organisations_level_query": {"queryType": "groupBy","dataSource": "","dimensions": ["organisation_id", "organisation_name"],"granularity": "all","intervals": "1901-01-01T00:00:00+00:00/2101-01-01T00:00:00+00:00","filter": {"type": "and","fields": []}}, - "program_block_level_query": {"queryType": "groupBy","dataSource": "ml-programusers-status","dimensions": ["block_id", "block_name"],"granularity": "all","intervals": "1901-01-01T00:00:00+00:00/2101-01-01T00:00:00+00:00","filter": {"type": "and","fields": []}} + "program_block_level_query": {"queryType": "groupBy","dataSource": "","dimensions": ["block_id", "block_name"],"granularity": "all","intervals": "1901-01-01T00:00:00+00:00/2101-01-01T00:00:00+00:00","filter": {"type": "and","fields": []}} } \ No newline at end of file diff --git a/common/enum.utils.js b/common/enum.utils.js index a07cee4..6397339 100644 --- a/common/enum.utils.js +++ b/common/enum.utils.js @@ -1,3 +1,14 @@ +/** + * name : enum.utils.js + * author : Ankit Shahu + * created-date : 10-April-2023 + * Description : This is to keep all the hard code value in form of variable. + */ + + +/** + * Description : projection passed by frontend + */ exports.ResourceTypeProjection = { DISTRICT:"district", BLOCK:"block", @@ -5,11 +16,17 @@ exports.ResourceTypeProjection = { } +/** + * Description : resource type passed by frontend + */ exports.ResourceType = { PROGRAM:"program", SOLUTION:"solution" } +/** + * Description : solution type passed by frontend + */ exports.SolutionType = { PROJECT : "improvementProject", OBSERVATION: "observation", diff --git a/common/utils.js b/common/utils.js index a0c281c..d5bc790 100644 --- a/common/utils.js +++ b/common/utils.js @@ -1,5 +1,5 @@ const druidQueries = require('./druid_queries.json'); - +const { ResourceType, SolutionType } = require("../common/enum.utils"); /** * Return druid query for the given query name * @function @@ -80,10 +80,42 @@ function getDruidIntervalDate( data ) { return isoSring; } +/** + * Returns Druid Data source Name + * @function + * @name getDataSourceName + * @returns {String} returns druid data source name. +*/ +function getDataSourceName (query, body){ + let dataSource + if(query.resourceType === ResourceType.PROGRAM){ + dataSource = process.env.PROGRAM_RESOURCE_DATASOURCE_NAME + }else { + dataSource = body.solutionType === SolutionType.PROJECT ? process.env.PROJECT_RESOURCE_DATASOURCE_NAME : body.solutionType === SolutionType.OBSERVATION ? process.env.OBSERVATION_RESOURCE_DATASOURCE_NAME : process.env.SURVEY_RESOURCE_DATASOURCE_NAME + } + return dataSource +} + +/** + * Returns Druid Query Filter + * @function + * @name getResourceFilter + * @returns {String} returns druid query filter +*/ +function getResourceFilter (query) { + const resourceFilter = { + type: "selector", + dimension: query.resourceType == ResourceType.SOLUTION ? "solution_id" : "program_id", + value: query.resourceId + } + return resourceFilter +} module.exports = { getDruidQuery: getDruidQuery, getDruidConnection: getDruidConnection, getGotenbergConnection: getGotenbergConnection, - getDruidIntervalDate: getDruidIntervalDate + getDruidIntervalDate: getDruidIntervalDate, + getDataSourceName: getDataSourceName, + getResourceFilter:getResourceFilter } diff --git a/controllers/v1/resource.js b/controllers/v1/resource.js index e711f65..a72a78b 100644 --- a/controllers/v1/resource.js +++ b/controllers/v1/resource.js @@ -58,6 +58,7 @@ const {ResourceType, ResourceTypeProjection} = require("../../common/enum.utils" */ exports.filtervalues = async function (req, res) { + //userExtension will validate whether user have access to the program as designer or manager. const userExtension = await resourceHelper.userExtensions(req,res); if(userExtension){ if(req.query.resourceType == ResourceType.PROGRAM || req.query.resourceType == ResourceType.SOLUTION){ diff --git a/helper/resource.js b/helper/resource.js index c36811f..aeef265 100644 --- a/helper/resource.js +++ b/helper/resource.js @@ -6,18 +6,19 @@ */ -const { ResourceType, SolutionType } = require("../common/enum.utils"); + const { ResourceType } = require("../common/enum.utils"); const rp = require('request-promise'); -const { get } = require("request"); const kendra_service = require("./kendra_service"); +const utils = require("../common/utils"); +//user-extension validation: this will check if user is program manager or program designer of particular porgram. exports.userExtensions = async function (req,res){ return new Promise(async function (resolve, reject) { try { let userExtensions = await kendra_service.getUserExtension(req.userDetails.token) if(userExtensions.status === 200){ for(let platformCode = 0; platformCode < userExtensions.result.platformRoles.length; platformCode++){ - if(userExtensions.result.platformRoles[platformCode].code === "PROGRAM_DESIGNER" || userExtensions.result.platformRoles[platformCode].code === "PROGRAM_MANAGER"){ + if((userExtensions.result.platformRoles[platformCode].code === "PROGRAM_DESIGNER" || userExtensions.result.platformRoles[platformCode].code === "PROGRAM_MANAGER") && (userExtensions.result.platformRoles[platformCode].programs.includes(req.body.programId))){ resolve(true) break; } @@ -27,25 +28,21 @@ exports.userExtensions = async function (req,res){ resolve(false); } }catch(error){ - console.log(error); + res.status(400).send({ + result: false, + message: err.message + }); } -})} - + }) +} +//this function will call druid and return all the districts to particular program or solution exports.getDistricts = async function(req,res){ return new Promise(async function (resolve, reject) { try { let bodyParam = req.query.resourceType === ResourceType.SOLUTION ? gen.utils.getDruidQuery("solution_distric_level_query") : gen.utils.getDruidQuery("program_distric_level_query"); - if(req.query.resourceType === ResourceType.PROGRAM){ - bodyParam.dataSource = process.env.PROGRAM_RESOURCE_DATASOURCE_NAME - }else { - bodyParam.dataSource = req.body.solutionType === SolutionType.PROJECT ? process.env.PROJECT_RESOURCE_DATASOURCE_NAME : req.body.solutionType === SolutionType.OBSERVATION ? process.env.OBSERVATION_RESOURCE_DATASOURCE_NAME : process.env.SURVEY_RESOURCE_DATASOURCE_NAME - } - const resourceFilter = { - type: "selector", - dimension: req.query.resourceType == ResourceType.SOLUTION ? "solution_id" : "program_id", - value: req.query.resourceId - } + bodyParam.dataSource = await utils.getDataSourceName(req.query, req.body) + const resourceFilter = await utils.getResourceFilter(req.query) bodyParam.filter.fields.push(resourceFilter) let options = gen.utils.getDruidConnection(); options.method = "POST"; @@ -58,26 +55,19 @@ exports.getDistricts = async function(req,res){ }catch(err){ res.status(400).send({ result: false, - message: 'INTERNAL_SERVER_ERROR' + message: err.message }); } }) } +//this function will call druid and return all the organisations to particular program or solution exports.getOrganisations = async function(req,res){ return new Promise(async function (resolve, reject) { try { let bodyParam = req.query.resourceType === ResourceType.SOLUTION ? gen.utils.getDruidQuery("solution_organisations_level_query") : gen.utils.getDruidQuery("program_organisations_level_query"); - if(req.query.resourceType === ResourceType.PROGRAM){ - bodyParam.dataSource = process.env.PROGRAM_RESOURCE_DATASOURCE_NAME - }else { - bodyParam.dataSource = req.body.solutionType === SolutionType.PROJECT ? process.env.PROJECT_RESOURCE_DATASOURCE_NAME : req.body.solutionType === SolutionType.OBSERVATION ? process.env.OBSERVATION_RESOURCE_DATASOURCE_NAME : process.env.SURVEY_RESOURCE_DATASOURCE_NAME - } - const resourceFilter = { - type: "selector", - dimension: req.query.resourceType == ResourceType.SOLUTION ? "solution_id" : "program_id", - value: req.query.resourceId - } + bodyParam.dataSource = await utils.getDataSourceName(req.query, req.body) + const resourceFilter = await utils.getResourceFilter(req.query) bodyParam.filter.fields.push(resourceFilter) let options = gen.utils.getDruidConnection(); options.method = "POST"; @@ -90,27 +80,20 @@ exports.getOrganisations = async function(req,res){ }catch(err){ res.status(400).send({ result: false, - message: 'INTERNAL_SERVER_ERROR'} - ); + message: err.message + }); } }) } +//this function will call druid and return all the block to particular program or solution exports.getBlocks = async function(req,res){ return new Promise(async function (resolve, reject) { try { let bodyParam = req.query.resourceType === ResourceType.SOLUTION ? gen.utils.getDruidQuery("solution_block_level_query") : gen.utils.getDruidQuery("program_block_level_query"); - if(req.query.resourceType === ResourceType.PROGRAM){ - bodyParam.dataSource = process.env.PROGRAM_RESOURCE_DATASOURCE_NAME - }else { - bodyParam.dataSource = req.body.solutionType === SolutionType.PROJECT ? process.env.PROJECT_RESOURCE_DATASOURCE_NAME : req.body.solutionType === SolutionType.OBSERVATION ? process.env.OBSERVATION_RESOURCE_DATASOURCE_NAME : process.env.SURVEY_RESOURCE_DATASOURCE_NAME - } - const resourceFilter = { - type: "selector", - dimension: req.query.resourceType == ResourceType.SOLUTION ? "solution_id" : "program_id", - value: req.query.resourceId - } + bodyParam.dataSource = await utils.getDataSourceName(req.query, req.body) + const resourceFilter = await utils.getResourceFilter(req.query) bodyParam.filter.fields.push(resourceFilter) const districtFilter = { @@ -130,8 +113,8 @@ exports.getBlocks = async function(req,res){ }catch(err){ res.status(400).send({ result: false, - message: 'INTERNAL_SERVER_ERROR'} - ); + message: err.message + }); } }) From abc5968650f502c0aec742f0e9733efe7104bb0f Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Mon, 10 Apr 2023 19:04:57 +0530 Subject: [PATCH 11/15] Added Reuseable functions and Resolving all the comments --- controllers/v1/resource.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/controllers/v1/resource.js b/controllers/v1/resource.js index a72a78b..1ba306f 100644 --- a/controllers/v1/resource.js +++ b/controllers/v1/resource.js @@ -21,7 +21,8 @@ const {ResourceType, ResourceTypeProjection} = require("../../common/enum.utils" "query":{ // optional required for block "districtLocationId": "b5c35cfc-6c1e-4266-94ef-a425c43c7f4e" } - "solutionType": "observation"/"survey"/"improvementProject" //Required only for resourceType=solution + "solutionType": "observation"/"survey"/"improvementProject" //Required only for resourceType=solution, + "programId": "6013eab15faeea0e88a26efd" } * @apiParamExample {json} Response: * { From 5e10877c446fdfe8022f4de9a090e5e5564a4f17 Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Mon, 10 Apr 2023 19:06:49 +0530 Subject: [PATCH 12/15] Added Reuseable functions and Resolving all the comments --- controllers/v1/resource.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/controllers/v1/resource.js b/controllers/v1/resource.js index 1ba306f..2588cc5 100644 --- a/controllers/v1/resource.js +++ b/controllers/v1/resource.js @@ -69,7 +69,9 @@ exports.filtervalues = async function (req, res) { }) } if(req.body.projection == ResourceTypeProjection.DISTRICT){ + //Gets list of district where program or solution started const getDistict = await resourceHelper.getDistricts( req ,res) + //Gets list of Organisation where program or solution started const getOrganisation = await resourceHelper.getOrganisations(req,res) if(getDistict || getOrganisation){ const districtOrganisationResponse = { @@ -83,6 +85,7 @@ exports.filtervalues = async function (req, res) { res.status(200).send(districtOrganisationResponse) } } else if(req.body.projection == ResourceTypeProjection.BLOCK){ + //Gets list of block where program or solution started const getBlock = await resourceHelper.getBlocks( req,res ) if(getBlock){ const blockResponse = { From 79a764d809955ca174fb32ab224fc986c66d21c8 Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Mon, 10 Apr 2023 19:09:58 +0530 Subject: [PATCH 13/15] Added Reuseable functions and Resolving all the comments --- helper/resource.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/helper/resource.js b/helper/resource.js index aeef265..8d06e63 100644 --- a/helper/resource.js +++ b/helper/resource.js @@ -41,7 +41,9 @@ exports.getDistricts = async function(req,res){ return new Promise(async function (resolve, reject) { try { let bodyParam = req.query.resourceType === ResourceType.SOLUTION ? gen.utils.getDruidQuery("solution_distric_level_query") : gen.utils.getDruidQuery("program_distric_level_query"); + //Gets data source name based on resource type and solution type bodyParam.dataSource = await utils.getDataSourceName(req.query, req.body) + //Gets Resource filter based on Resource type const resourceFilter = await utils.getResourceFilter(req.query) bodyParam.filter.fields.push(resourceFilter) let options = gen.utils.getDruidConnection(); @@ -66,7 +68,9 @@ exports.getOrganisations = async function(req,res){ return new Promise(async function (resolve, reject) { try { let bodyParam = req.query.resourceType === ResourceType.SOLUTION ? gen.utils.getDruidQuery("solution_organisations_level_query") : gen.utils.getDruidQuery("program_organisations_level_query"); + //Gets data source name based on resource type and solution type bodyParam.dataSource = await utils.getDataSourceName(req.query, req.body) + //Gets Resource filter based on Resource type const resourceFilter = await utils.getResourceFilter(req.query) bodyParam.filter.fields.push(resourceFilter) let options = gen.utils.getDruidConnection(); @@ -92,7 +96,9 @@ exports.getBlocks = async function(req,res){ return new Promise(async function (resolve, reject) { try { let bodyParam = req.query.resourceType === ResourceType.SOLUTION ? gen.utils.getDruidQuery("solution_block_level_query") : gen.utils.getDruidQuery("program_block_level_query"); + //Gets data source name based on resource type and solution type bodyParam.dataSource = await utils.getDataSourceName(req.query, req.body) + //Gets Resource filter based on Resource type const resourceFilter = await utils.getResourceFilter(req.query) bodyParam.filter.fields.push(resourceFilter) From 154b246a5c14e77f27b9534f3aaf23acf94be5ba Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Mon, 10 Apr 2023 21:03:51 +0530 Subject: [PATCH 14/15] Fixed code as per comment --- .env.sample | 6 +++--- common/{enum.utils.js => constants.js} | 0 common/utils.js | 11 +++++++++-- controllers/v1/resource.js | 2 +- helper/resource.js | 10 ++++++---- 5 files changed, 19 insertions(+), 10 deletions(-) rename common/{enum.utils.js => constants.js} (100%) diff --git a/.env.sample b/.env.sample index 3366327..a468605 100644 --- a/.env.sample +++ b/.env.sample @@ -10,9 +10,9 @@ OBSERVATION_DATASOURCE_NAME = "OBSERVATION_DATASOURCE_NAME" // Obs OBSERVATION_EVIDENCE_DATASOURCE_NAME = "EVIDENCE_DATASOURCE_NAME" // Observation evidences data source name SURVEY_DATASOURCE_NAME = "SURVEY_DATASOURCE_NAME" // Survey data source name SURVEY_EVIDENCE_DATASOURCE_NAME = "SURVEY_EVIDENCE_DATASOURCE_NAME" // Survey evidence data source name -PROJECT_RESOURCE_DATASOURCE_NAME = "PROJECT_RESOURCE_DATASOURCE_NAME" // project resource data source name -OBSERVATION_RESOURCE_DATASOURCE_NAME = "OBSERVATION_RESOURCE_DATASOURCE_NAME" // observation resource data source name -SURVEY_RESOURCE_DATASOURCE_NAME = "SURVEY_RESOURCE_DATASOURCE_NAME" // survey resource data source name +PROJECT_RESOURCE_DATASOURCE_NAME = "PROJECT_RESOURCE_DATASOURCE_NAME" // Project resource data source name +OBSERVATION_RESOURCE_DATASOURCE_NAME = "OBSERVATION_RESOURCE_DATASOURCE_NAME" // Observation resource data source name +SURVEY_RESOURCE_DATASOURCE_NAME = "SURVEY_RESOURCE_DATASOURCE_NAME" // Survey resource data source name PROGRAM_RESOURCE_DATASOURCE_NAME = "PROGRAM_RESOURCE_DATASOURCE_NAME" // Program resource data source name CONTENT_REPORT_THRESHOLD = 5 // Restrict number of records to be shown for container reports ENTITY_SCORE_REPORT_THRESHOLD = 5 // Restrict number of submission for entity score report diff --git a/common/enum.utils.js b/common/constants.js similarity index 100% rename from common/enum.utils.js rename to common/constants.js diff --git a/common/utils.js b/common/utils.js index d5bc790..e38bbe5 100644 --- a/common/utils.js +++ b/common/utils.js @@ -1,5 +1,5 @@ const druidQueries = require('./druid_queries.json'); -const { ResourceType, SolutionType } = require("../common/enum.utils"); +const { ResourceType, SolutionType } = require("./constants"); /** * Return druid query for the given query name * @function @@ -91,7 +91,14 @@ function getDataSourceName (query, body){ if(query.resourceType === ResourceType.PROGRAM){ dataSource = process.env.PROGRAM_RESOURCE_DATASOURCE_NAME }else { - dataSource = body.solutionType === SolutionType.PROJECT ? process.env.PROJECT_RESOURCE_DATASOURCE_NAME : body.solutionType === SolutionType.OBSERVATION ? process.env.OBSERVATION_RESOURCE_DATASOURCE_NAME : process.env.SURVEY_RESOURCE_DATASOURCE_NAME + switch (body.solutionType) { + case SolutionType.PROJECT : dataSource = process.env.PROJECT_RESOURCE_DATASOURCE_NAME + break; + case SolutionType.OBSERVATION : dataSource = process.env.OBSERVATION_RESOURCE_DATASOURCE_NAME + break; + case SolutionType.SURVEY : dataSource = process.env.SURVEY_RESOURCE_DATASOURCE_NAME + break; + } } return dataSource } diff --git a/controllers/v1/resource.js b/controllers/v1/resource.js index 2588cc5..e1cbb83 100644 --- a/controllers/v1/resource.js +++ b/controllers/v1/resource.js @@ -7,7 +7,7 @@ const resourceHelper = require("../../helper/resource") -const {ResourceType, ResourceTypeProjection} = require("../../common/enum.utils") +const {ResourceType, ResourceTypeProjection} = require("../../common/constants") /** * @api {post} /mlreports/api/v1/resource/filtervalues?resourceType=program&resourceId=6013eab15faeea0e88a26ef5 diff --git a/helper/resource.js b/helper/resource.js index 8d06e63..80adef5 100644 --- a/helper/resource.js +++ b/helper/resource.js @@ -6,7 +6,7 @@ */ - const { ResourceType } = require("../common/enum.utils"); + const { ResourceType } = require("../common/constants"); const rp = require('request-promise'); const kendra_service = require("./kendra_service"); const utils = require("../common/utils"); @@ -51,7 +51,8 @@ exports.getDistricts = async function(req,res){ options.body = bodyParam; let data = await rp(options); if(data){ - const result = data.map(district => ({ id: req.query.resourceType == ResourceType.SOLUTION ? district.event.district_externalId : district.event.district_id, name: district.event.district_name })); + const typeOfId = req.query.resourceType == ResourceType.SOLUTION ? "district_externalId" : "district_id" + const result = data.map(district => ({ id: district.event[typeOfId] , name: district.event.district_name })); resolve(result) } }catch(err){ @@ -78,7 +79,7 @@ exports.getOrganisations = async function(req,res){ options.body = bodyParam; let data = await rp(options); if(data){ - const result = data.map(district => ({ id: district.event.organisation_id, name: district.event.organisation_name })); + const result = data.map(organisation => ({ id: organisation.event.organisation_id, name: organisation.event.organisation_name })); resolve(result) } }catch(err){ @@ -113,7 +114,8 @@ exports.getBlocks = async function(req,res){ options.body = bodyParam; let data = await rp(options); if(data){ - const result = data.map(block => ({ id: req.query.resourceType == ResourceType.SOLUTION ? block.event.block_externalId : block.event.block_id, name: block.event.block_name })); + const typeOfId = req.query.resourceType == ResourceType.SOLUTION ? "block_externalId" : "block_id" + const result = data.map(block => ({ id: block.event[typeOfId] , name: block.event.block_name })); resolve(result) } }catch(err){ From 54c6dbb0967631536291e9d1f74bf328c8344c91 Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Tue, 11 Apr 2023 06:50:19 +0530 Subject: [PATCH 15/15] Fixed code as per comment --- common/constants.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/constants.js b/common/constants.js index 6397339..6ae2a49 100644 --- a/common/constants.js +++ b/common/constants.js @@ -1,5 +1,5 @@ /** - * name : enum.utils.js + * name : constants.js * author : Ankit Shahu * created-date : 10-April-2023 * Description : This is to keep all the hard code value in form of variable.