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

Entity generalization #73

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d775750
cache file
priyanka-TL Feb 22, 2022
1141694
package.json
priyanka-TL Feb 22, 2022
9a2f580
console removed
VISHNUDAS-tunerlabs Mar 7, 2022
0add1df
Merge branch 'entityGeneralization' of https://github.com/shikshaloka…
VISHNUDAS-tunerlabs Mar 7, 2022
fd2eab1
entity Generalization ml-survey march 21
VISHNUDAS-tunerlabs Mar 21, 2022
3fa52cf
time out fn change in learners search
VISHNUDAS-tunerlabs Mar 24, 2022
7502566
listByLocationIds change
VISHNUDAS-tunerlabs Mar 24, 2022
87983a8
assessment api timeout error resolve
VISHNUDAS-tunerlabs Mar 25, 2022
a81ef01
observations/entities self review
VISHNUDAS-tunerlabs Mar 25, 2022
6f7174e
self review- observation Submissions create
VISHNUDAS-tunerlabs Mar 25, 2022
008aa05
ml-survey review comment resolve lvl 1
VISHNUDAS-tunerlabs Mar 30, 2022
53a6c85
req data change
VISHNUDAS-tunerlabs Mar 30, 2022
4652a91
externalId added with name
VISHNUDAS-tunerlabs Mar 30, 2022
83b4be6
externalId added with name 2
VISHNUDAS-tunerlabs Mar 30, 2022
9a6c097
eg changes
VISHNUDAS-tunerlabs Apr 4, 2022
dbad1b2
org fuzzy search added
VISHNUDAS-tunerlabs Jun 20, 2022
db27f15
typo resolve
VISHNUDAS-tunerlabs Jul 20, 2022
187ebfe
extraline remove
VISHNUDAS-tunerlabs Jul 20, 2022
86230fa
extraline remove
VISHNUDAS-tunerlabs Jul 20, 2022
b14b696
resolve
VISHNUDAS-tunerlabs Jul 20, 2022
5fdc70a
comments removed
VISHNUDAS-tunerlabs Jul 20, 2022
df333ec
user resd added
VISHNUDAS-tunerlabs Jul 20, 2022
84940b5
resolves
VISHNUDAS-tunerlabs Jul 20, 2022
444ad07
changed to resolve
VISHNUDAS-tunerlabs Jul 20, 2022
ce073f0
formated
VISHNUDAS-tunerlabs Jul 20, 2022
0d6010f
sunbird.js removed functions added to users
VISHNUDAS-tunerlabs Jul 22, 2022
f9376d4
code check added
VISHNUDAS-tunerlabs Aug 5, 2022
a542c6e
comment removed
VISHNUDAS-tunerlabs Aug 8, 2022
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
103 changes: 52 additions & 51 deletions controllers/v1/observationSubmissionsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const criteriaHelper = require(MODULES_BASE_PATH + "/criteria/helper")
const questionsHelper = require(MODULES_BASE_PATH + "/questions/helper")
const observationSubmissionsHelper = require(MODULES_BASE_PATH + "/observationSubmissions/helper")
const scoringHelper = require(MODULES_BASE_PATH + "/scoring/helper")
const sunbirdService = require(ROOT_PATH + "/generics/services/sunbird");

/**
* ObservationSubmissions
Expand Down Expand Up @@ -88,7 +89,7 @@ module.exports = class ObservationSubmissions extends Abstract {
* @name create
* @param {Object} req -request data.
* @param {String} req.params._id -observation solution id.
* @param {String} req.query.entityId -entity id.
* @param {String} req.query.entityId -location id.
* @param {String} req.userDetails.userId - logged in user id.
* @returns {JSON} - observation submissions creation.
*/
Expand All @@ -97,45 +98,43 @@ module.exports = class ObservationSubmissions extends Abstract {
return new Promise(async (resolve, reject) => {

try {

let observationDocument = await observationsHelper.observationDocuments({
_id: req.params._id,
createdBy: req.userDetails.userId,
status: {$ne:"inactive"},
entities: ObjectId(req.query.entityId)
entities: req.query.entityId
});

if (!observationDocument[0]) {
return resolve({
status: httpStatusCode.bad_request.status,
message: messageConstants.apiResponses.OBSERVATION_NOT_FOUND
});
}

observationDocument = observationDocument[0];

let entityDocument = await entitiesHelper.entityDocuments({
_id: req.query.entityId,
entityType: observationDocument.entityType
}, [
"metaInformation",
"entityTypeId",
"entityType",
"registryDetails"
]);
let filterData = {
"id" : req.query.entityId,
"type" : observationDocument.entityType
};

if (!entityDocument[0]) {
return resolve({
status: httpStatusCode.bad_request.status,
message: messageConstants.apiResponses.ENTITY_NOT_FOUND
});
}
let entitiesDocument = await sunbirdService.learnerLocationSearch( filterData );

entityDocument = entityDocument[0];

if (entityDocument.registryDetails && Object.keys(entityDocument.registryDetails).length > 0) {
entityDocument.metaInformation.registryDetails = entityDocument.registryDetails;
if ( !entitiesDocument.success || !entitiesDocument.data || !entitiesDocument.data.response.length > 0 ) {
return resolve({
status: httpStatusCode.bad_request.status,
message: messageConstants.apiResponses.ENTITY_NOT_FOUND
});
}


let entityResult = entitiesDocument.data.response;
let entityData = await entitiesHelper.extractDataFromLocationResult(entityResult);
let entityDocument = entityData[0]

entityDocument.metaInformation.registryDetails = entityDocument.registryDetails;

let solutionDocument = await solutionsHelper.solutionDocuments({
_id: observationDocument.solutionId,
status: "active",
Expand All @@ -145,7 +144,6 @@ module.exports = class ObservationSubmissions extends Abstract {
"frameworkId",
"frameworkExternalId",
"evidenceMethods",
"entityTypeId",
"entityType",
"programId",
"programExternalId",
Expand All @@ -165,19 +163,20 @@ module.exports = class ObservationSubmissions extends Abstract {
}

solutionDocument = solutionDocument[0];

let entityProfileForm = await database.models.entityTypes.findOne(
solutionDocument.entityTypeId,
{
profileForm: 1
}
).lean();

if (!entityProfileForm) {
return resolve({
status: httpStatusCode.bad_request.status,
message: messageConstants.apiResponses.ENTITY_PROFILE_FORM_NOT_FOUND });
}

//need to check usage of entityProfileForm, why it is fetched. if needed create new logic
// let entityProfileForm = await database.models.entityTypes.findOne(
// solutionDocument.entityTypeId,
// {
// profileForm: 1
// }
// ).lean();

// if (!entityProfileForm) {
// return resolve({
// status: httpStatusCode.bad_request.status,
// message: messageConstants.apiResponses.ENTITY_PROFILE_FORM_NOT_FOUND });
// }

let lastSubmissionNumber = 0;

Expand All @@ -192,7 +191,7 @@ module.exports = class ObservationSubmissions extends Abstract {


let submissionDocument = {
entityId: entityDocument._id,
entityId: entityDocument.id,
entityExternalId: (entityDocument.metaInformation.externalId) ? entityDocument.metaInformation.externalId : "",
entityInformation: entityDocument.metaInformation,
solutionId: solutionDocument._id,
Expand All @@ -202,7 +201,6 @@ module.exports = class ObservationSubmissions extends Abstract {
isAPrivateProgram : solutionDocument.isAPrivateProgram,
frameworkId: solutionDocument.frameworkId,
frameworkExternalId: solutionDocument.frameworkExternalId,
entityTypeId: solutionDocument.entityTypeId,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VISHNUDAS-tunerlabs check with frontend that entityTypeId using anywhere in the app

entityType: solutionDocument.entityType,
observationId: observationDocument._id,
observationInformation: {
Expand Down Expand Up @@ -302,29 +300,32 @@ module.exports = class ObservationSubmissions extends Abstract {
req.headers["x-app-ver"] ? req.headers["x-app-ver"] :
req.headers.appversion;
}

let newObservationSubmissionDocument = await database.models.observationSubmissions.create(submissionDocument);

if( newObservationSubmissionDocument.referenceFrom === messageConstants.common.PROJECT ) {
await observationSubmissionsHelper.pushSubmissionToImprovementService(
_.pick(newObservationSubmissionDocument,["project","status","_id"])
);
}

// Push new observation submission to kafka for reporting/tracking.

observationSubmissionsHelper.pushObservationSubmissionForReporting(newObservationSubmissionDocument._id);


VISHNUDAS-tunerlabs marked this conversation as resolved.
Show resolved Hide resolved

let observations = new Array;

observations = await observationsHelper.listV2(req.userDetails.userId);


let responseMessage = messageConstants.apiResponses.OBSERVATION_SUBMISSION_CREATED;

return resolve({
message: responseMessage,
result: observations
});

});
} catch (error) {
return reject({
status: error.status || httpStatusCode.internal_server_error.status,
Expand Down Expand Up @@ -806,7 +807,7 @@ module.exports = class ObservationSubmissions extends Abstract {

let createdBy = req.query.createdBy;
let solutionId = req.query.solutionId;
let entityId = req.params._id;
let code = req.params._id;
let submissionNumber = (req.query.submissionNumber) ? parseInt(req.query.submissionNumber) : 1;

if (!createdBy) {
Expand All @@ -817,11 +818,11 @@ module.exports = class ObservationSubmissions extends Abstract {
throw messageConstants.apiResponses.SOLUTION_ID_NOT_FOUND;
}

if (!entityId) {
if (!code) {
throw messageConstants.apiResponses.ENTITY_ID_NOT_FOUND;
}


let solutionDocument = await database.models.solutions.findOne({
externalId: solutionId,
type : "observation",
Expand All @@ -837,7 +838,7 @@ module.exports = class ObservationSubmissions extends Abstract {

let queryObject = {
"createdBy": createdBy,
"entityExternalId": entityId,
"entityExternalId": code,
"solutionExternalId": solutionId,
"submissionNumber" : (submissionNumber) ? submissionNumber : 1
}
Expand All @@ -846,7 +847,7 @@ module.exports = class ObservationSubmissions extends Abstract {
queryObject,
{ "answers": 1, "criteria": 1, "evidencesStatus": 1, "entityInformation": 1, "entityProfile": 1, "solutionExternalId": 1 , "scoringSystem" : 1}
).lean();

if (!submissionDocument._id) {
throw messageConstants.apiResponses.SUBMISSION_NOT_FOUND
}
Expand Down
Loading