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

changes done for story 23909 #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
121 changes: 0 additions & 121 deletions module/userProjects/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -1712,127 +1712,6 @@ module.exports = class UserProjectsHelper {
})
}

/**
* User assigned project creation data.
* @method
* @name userAssignedProjectCreation
* @param {String} templateId - Project template id.
* @param {String} userId - Logged in user id.
* @param {String} userToken - Logged in user token.
* @returns {String} - message.
*/

static userAssignedProjectCreation(templateId, userId, userToken) {
return new Promise(async (resolve, reject) => {
try {

const projectTemplateData =
await projectTemplatesHelper.templateDocument({
status: CONSTANTS.common.PUBLISHED,
_id: templateId,
isReusable: false
}, "all",
[
"ratings",
"noOfRatings",
"averageRating"
]);

if (!projectTemplateData.length > 0) {
throw {
message: CONSTANTS.apiResponses.SOLUTION_NOT_FOUND,
status: HTTP_STATUS_CODE['bad_request'].status
}
}

let result = { ...projectTemplateData[0] };

result.projectTemplateId = result._id;
result.projectTemplateExternalId = result.externalId;
result.userId = userId;
result.createdBy = userId;
result.updatedBy = userId;

let userOrganisations =
await kendraService.getUserOrganisationsAndRootOrganisations(
userToken,
userId
);

if (!userOrganisations.success) {
throw {
message: CONSTANTS.apiResponses.USER_ORGANISATION_NOT_FOUND,
status: HTTP_STATUS_CODE['bad_request'].status
}
}

result.createdFor =
userOrganisations.data.createdFor;

result.rootOrganisations =
userOrganisations.data.rootOrganisations;

result.assesmentOrObservationTask = false;

if (projectTemplateData[0].tasks && projectTemplateData[0].tasks.length > 0) {

const tasksAndSubTasks =
await projectTemplatesHelper.tasksAndSubTasks(
projectTemplateData[0]._id
);

if (tasksAndSubTasks.length > 0) {

result.tasks = _projectTask(tasksAndSubTasks);

result.tasks.forEach(task => {
if (
task.type === CONSTANTS.common.ASSESSMENT ||
task.type === CONSTANTS.common.OBSERVATION
) {
result.assesmentOrObservationTask = true;
}
});


let taskReport = {
total: result.tasks.length
};

result.tasks.forEach(task => {
if (!taskReport[task.status]) {
taskReport[task.status] = 1;
} else {
taskReport[task.status] += 1;
}
});

result["taskReport"] = taskReport;

}
}

delete result._id;

return resolve({
success: true,
message: CONSTANTS.apiResponses.UPDATED_DOCUMENT_SUCCESSFULLY,
data: result
});

} catch (error) {
return resolve({
status:
error.status ?
error.status : HTTP_STATUS_CODE['internal_server_error'].status,
success: false,
message: error.message,
data: {}
});
}
});
}

/**
* Get list of user projects with the targetted ones.
* @method
Expand Down
3 changes: 0 additions & 3 deletions module/userProjects/validator/v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ module.exports = (req) => {
req.checkParams('_id').exists().withMessage("required project id");
req.checkQuery('lastDownloadedAt').exists().withMessage("required last downloaded at");
},
details : function () {
req.checkParams('_id').exists().withMessage("required project id");
},
tasksStatus : function () {
req.checkParams('_id').exists().withMessage("required project id");
},
Expand Down