forked from project-sunbird/ml-survey-service
-
Notifications
You must be signed in to change notification settings - Fork 11
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 #83
Open
aishwa8141
wants to merge
7
commits into
shikshalokam:master
Choose a base branch
from
aishwa8141:mapObservation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
23cb5e9
created new apis : map observation
f1fd4b9
Merge branch 'master' of https://github.com/shikshalokam/ml-survey-se…
3849cfb
created new apis : map observation
32b8c6a
added sample env
0842a2c
review changes
b612bad
review changes
4d3f002
removed unused variables
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aishwa8141 instead of new API can we use update API in https://github.com/shikshalokam/ml-survey-service/blob/master/controllers/v1/solutionsController.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aks30 these new Api is calling update question set and publish question set API's and updating mongo object
And in the existing API requires solutionExternalId