Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Api's : Map newly created Observation to Program and Update any QuestionSet #84

Open
wants to merge 7 commits into
base: quml-consumption-apis
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ ML_PROJECT_SERVICE_URL = "http://ml-project-service:3000"

KEYCLOAK_PUBLIC_KEY_PATH = "keycloak-public-keys" // Keycloak public keys path

DISABLE_LEARNER_SERVICE_ON_OFF = "ON" // Disable learner service check
DISABLE_LEARNER_SERVICE_ON_OFF = "ON" // Disable learner service check

CREATION_PORTAL_URL = "https://dock.sunbirded.org" // creation portal url

CREATION_PORTAL_AUTHORIZATION_KEY = "" // creation portal authorization key
103 changes: 103 additions & 0 deletions controllers/v1/programsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -762,4 +762,107 @@ module.exports = class Programs extends Abstract {
})
}


/**
* @api {post} /programs/mapObservation
* @apiVersion 1.0.0
* @apiName mapObservation
* @apiGroup Program
* @apiSampleRequest /programs/mapObservation
*{
"programId": "5f34e44681871d939950bca5",
"questionsetId": "do_1135353079207444481964",
"createdFor": [
"ShikshaLokam"
],
"name": "ShikshaLokam-QS"
}
* @apiParamExample {json} Response:
{
"message": "mapped obsertion to program successfully",
"status": 200,
"result": {
"do_1135353079207444481964": "do_11357345389617152011677",
"do_11357345389617152011677": "62c287307d70ae36aaf96cd3"
}
}

/**
* Map Observation to program.
* @method
* @name mapObservation
* @param {Object} req - requested data.
* @returns {JSON} -
*/

async mapObservation(req) {
return new Promise(async (resolve, reject) => {
try {

let programUpdated = await programsHelper.mapObservation(
req.body.programId,req.body.questionsetId,{
createdFor: req.body.createdFor,
createdBy: req.userDetails.userId,
name: req.body.name
}
);

return resolve(programUpdated);

} catch (error) {
return reject({
status: error.status || httpStatusCode.internal_server_error.status,
message: error.message || httpStatusCode.internal_server_error.message,
errorObject: error
});
}
});
}


/**
* @api {post} /programs/updateMapObservation/:solutionId
* @apiVersion 1.0.0
* @apiName mapObservation
* @apiGroup Program
* @apiParam {String} SolutionId Solution ID.
* @apiSampleRequest /programs/updateMapObservation
*{
"name": "ShikshaLokam",
"desciption": "",
"startDate": "2021-02-01",
"endDate": "2021-02-05",
"status": "published"
}
* @apiParamExample {json} Response:
{
"message": "Observation successfully updated.",
"status": 200
}
/**
* updateMapObservation.
* @method
* @name updateMapObservation
* @param {Object} req - requested data.
* @returns {JSON} -
*/
async updateMapObservation(req) {
return new Promise(async (resolve, reject) => {
try {

let programUpdated = await programsHelper.mapUpdateObservation(
req.params._id,req.body

);

return resolve(programUpdated);
} catch (error) {
return reject({
status: error.status || httpStatusCode.internal_server_error.status,
message: error.message || httpStatusCode.internal_server_error.message
});
}
});
}

};
4 changes: 3 additions & 1 deletion generics/messageConstants/apiResponses.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,5 +368,7 @@ module.exports = {
"SOLUTION_NOT_FOUND_OR_NOT_A_TARGETED": "Solution is not targeted to the role",
"OBSERVATION_SUBMISSION_FOUND" : "Observation submission fetched successfully",
"SURVEY_SUBMISSION_FOUND": "Survey submission fetched successfully",
"SOLUTION_ID_AND_USERPROFILE_REQUIRED": "Required solution Id and userProfile"
"SOLUTION_ID_AND_USERPROFILE_REQUIRED": "Required solution Id and userProfile",
"QUESTIONSET_NOT_FOUND": "Question set not found"

}
7 changes: 6 additions & 1 deletion generics/messageConstants/endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,10 @@ module.exports = {
GET_PROJECT_TEMPLATE_LISTS : "/v1/project/templates/listByIds",
DOWNLOADABLE_FILE_URL: "/v1/cloud-services/files/getDownloadableUrl",
USER_READ : "/user/v1/read",
USER_READ_V5 : "/v5/user/read"
USER_READ_V5 : "/v5/user/read",
COPY_QUESTION_SET: "/api/questionset/v1/copy",
READ_QUESTION_SET: "/action/questionset/v1/hierarchy",
UPDATE_QUESTION_SET_HIERARCHY: "/api/questionset/v1/hierarchy/update",
PUBLISH_QUESTION_SET: "/api/questionset/v1/publish",
UPDATE_QUESTION_SET:"/api/questionset/v1/update"
}
174 changes: 174 additions & 0 deletions generics/services/questionset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@

const request = require('request');
const CREATION_PORTAL_URL = process.env.CREATION_PORTAL_URL


const copyQuestionSet = function (copyReq, questionSetId) {
const copyQuestionSetUrl = CREATION_PORTAL_URL + messageConstants.endpoints.COPY_QUESTION_SET + "/" + questionSetId;
const headers = {
"content-type": "application/json",
"Authorization": "Bearer " + process.env.CREATION_PORTAL_AUTHORIZATION_KEY
}
const options = {
headers,
json: { request: { questionset: copyReq } }
};
console.log("")


return new Promise((resolve, reject) => {
try {

const copyQuestionSetCallback = function (err, data) {
if (err || data.statusCode != 200) {
return reject({
message: messageConstants.apiResponses.QUESTIONSET_NOT_FOUND,
status: httpStatusCode.bad_request.status,
})
} else if (data.statusCode == 200) {
let response = data.body
return resolve(response);

}
}
request.post(copyQuestionSetUrl, options, copyQuestionSetCallback)

} catch (error) {
return reject(error);
}
})

}

const readQuestionSet = function (copiedQuestionsetId) {
return new Promise((resolve, reject) => {
try {

let url = CREATION_PORTAL_URL + messageConstants.endpoints.READ_QUESTION_SET + "/" + copiedQuestionsetId + "?mode=edit";
const headers = {
"content-type": "application/json",
"Authorization": "Bearer " + process.env.CREATION_PORTAL_AUTHORIZATION_KEY
}
const readQuestionSetCallBack = function (err, data) {
if (err || data.statusCode != 200) {
return reject({
message: messageConstants.apiResponses.QUESTIONSET_NOT_FOUND,
status: httpStatusCode.bad_request.status,
})
} else if (data.statusCode == 200) {
let readRes = JSON.parse(data.body)
return resolve(readRes)
}
}
request.get(url, { headers: headers }, readQuestionSetCallBack)

} catch (error) {
console.log("errt", error)
return reject(error);
}
})

}

const updateQuestionSetHierarchy = function (req) {
return new Promise((resolve, reject) => {
try {

let updateUrl = CREATION_PORTAL_URL + messageConstants.endpoints.UPDATE_QUESTION_SET_HIERARCHY;
const headers = {
"content-type": "application/json",
"Authorization": "Bearer " + process.env.CREATION_PORTAL_AUTHORIZATION_KEY
}
function updateQuestionSetHierarchyCallBack(err, data) {
if (err || data.statusCode != 200) {
return reject({
message: messageConstants.apiResponses.QUESTIONSET_NOT_FOUND,
status: httpStatusCode.bad_request.status,
})
} else if (data.statusCode == 200) {
return resolve({
status: data.statusCode
})
}
}
request.patch(updateUrl, { headers: headers, json: true, json: req }, updateQuestionSetHierarchyCallBack)

} catch (error) {
return reject(error);
}
})

}

const publishQuestionSet = function (questionsetId) {
return new Promise((resolve, reject) => {
try {

let publishUrl = `${CREATION_PORTAL_URL}${messageConstants.endpoints.PUBLISH_QUESTION_SET}/${questionsetId}`;
const headers = {
"content-type": "application/json",
"Authorization": "Bearer " + process.env.CREATION_PORTAL_AUTHORIZATION_KEY
}
async function publishQuestionSetCallBack(err, data) {
if (err || data.statusCode != 200) {
const errmsg = JSON.parse(data.body)
return reject({
message: errmsg.errmsg || messageConstants.apiResponses.QUESTIONSET_NOT_FOUND,
status: httpStatusCode.bad_request.status,
})
} else if (data.statusCode == 200) {
return resolve({
status: data.statusCode

})
}
}
request.post(publishUrl, { headers: headers }, publishQuestionSetCallBack)

} catch (error) {
return reject(error);
}
})

}

const updateQuestionSet = function (updateReq, migratedId) {
return new Promise((resolve, reject) => {
try {
const headers = {
"content-type": "application/json",
"Authorization": "Bearer " + process.env.CREATION_PORTAL_AUTHORIZATION_KEY
}
let updateUrl = CREATION_PORTAL_URL + messageConstants.endpoints.UPDATE_QUESTION_SET + "/" + migratedId;
const options = {
headers,
json: true,
json: { request: { questionset: updateReq } }
};
function updateQuestionSetCallBack(err, data) {
if (err || data.statusCode != 200) {
return reject({
message: messageConstants.apiResponses.QUESTIONSET_NOT_FOUND,
status: httpStatusCode.bad_request.status,
})
} else if(data.statusCode == 200) {
return resolve({
status: data.statusCode
})
}
}
request.patch(updateUrl, options, updateQuestionSetCallBack)

} catch (error) {
return reject(error);
}
})
}

module.exports = {
copyQuestionSet: copyQuestionSet,
readQuestionSet: readQuestionSet,
updateQuestionSetHierarchy: updateQuestionSetHierarchy,
publishQuestionSet: publishQuestionSet,
updateQuestionSet: updateQuestionSet
};
3 changes: 2 additions & 1 deletion models/solutions.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ module.exports = {
registry: Array,
frameworkId: "ObjectId",
frameworkExternalId: String,
migratedId:String,
parentSolutionId: "ObjectId",
noOfRatingLevels: Number,
isRubricDriven: { type : Boolean, default: false },
Expand Down Expand Up @@ -134,5 +135,5 @@ module.exports = {
default: 1
},
reportInformation : Object
}
},
};
Loading