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 reverted #116

Open
wants to merge 1 commit 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
4 changes: 2 additions & 2 deletions generics/services/certificate.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ const createCertificate = function (bodyData) {
try {

const ML_PROJECT_URL = `http://${process.env.SERVICE_NAME}:${process.env.APPLICATION_PORT}`;
const callbackUrl = ML_PROJECT_URL + CONSTANTS.endpoints.PROJECT_CERTIFICATE_API_CALLBACK;
// const callbackUrl = ML_PROJECT_URL + CONSTANTS.endpoints.PROJECT_CERTIFICATE_API_CALLBACK;
let certificateCreateUrl =
process.env.CERTIFICATE_SERVICE_URL +
CONSTANTS.endpoints.CERTIFICATE_CREATE + "?mode=async&callback=" + callbackUrl;
CONSTANTS.endpoints.CERTIFICATE_CREATE //+ "?mode=async&callback=" + callbackUrl;
const options = {
headers : {
"content-type": "application/json"
Expand Down
281 changes: 104 additions & 177 deletions module/userProjects/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -1895,153 +1895,114 @@ module.exports = class UserProjectsHelper {
* @returns {Object}
*/

static userAssigned( userId,pageSize,pageNo,search, filter ) {
return new Promise(async (resolve, reject) => {
try {

let query = {
userId : userId,
isDeleted : false
}

let searchQuery = [];

if (search !== "") {
searchQuery = [
{ "title" : new RegExp(search, 'i') },
{ "description" : new RegExp(search, 'i') }
];
}

if ( filter && filter !== "" ) {
if( filter === CONSTANTS.common.CREATED_BY_ME ) {
query["referenceFrom"] = {
$ne : CONSTANTS.common.LINK
};
query["isAPrivateProgram"] = {
$ne : false
};
} else if( filter == CONSTANTS.common.ASSIGN_TO_ME ) {
query["isAPrivateProgram"] = false;
} else{
query["referenceFrom"] = CONSTANTS.common.LINK;
static userAssigned( userId,pageSize,pageNo,search, filter ) {
return new Promise(async (resolve, reject) => {
try {

let query = {
userId : userId,
isDeleted : false
}
}

let projects = await this.projects(
query,
pageSize,
pageNo,
searchQuery,
[
"title",
"description",
"solutionId",
"programId",
"programInformation.name",
"projectTemplateId",
"solutionExternalId",
"lastDownloadedAt",
"hasAcceptedTAndC",
"referenceFrom",
"status",
"certificate"
]
);

let totalCount = 0;
let data = [];

if( projects.success && projects.data && projects.data.data && Object.keys(projects.data.data).length > 0 ) {

totalCount = projects.data.count;
data = projects.data.data;

let searchQuery = [];

if (search !== "") {
searchQuery = [
{ "title" : new RegExp(search, 'i') },
{ "description" : new RegExp(search, 'i') }
];
}

if ( filter && filter !== "" ) {
if( filter === CONSTANTS.common.CREATED_BY_ME ) {
query["referenceFrom"] = {
$ne : CONSTANTS.common.LINK
};
query["isAPrivateProgram"] = {
$ne : false
};
} else if( filter == CONSTANTS.common.ASSIGN_TO_ME ) {
query["isAPrivateProgram"] = false;
} else{
query["referenceFrom"] = CONSTANTS.common.LINK;
}
}

let projects = await this.projects(
query,
pageSize,
pageNo,
searchQuery,
[
"title",
"description",
"solutionId",
"programId",
"programInformation.name",
"projectTemplateId",
"solutionExternalId",
"lastDownloadedAt",
"hasAcceptedTAndC",
"referenceFrom",
"status",
"certificate"
]
);

let totalCount = 0;
let data = [];

if( data.length > 0 ) {
let templateFilePath = [];
data.forEach( projectData => {

projectData.name = projectData.title;


if (projectData.programInformation) {
projectData.programName = projectData.programInformation.name;
delete projectData.programInformation;
}

if (projectData.solutionExternalId) {
projectData.externalId = projectData.solutionExternalId;
delete projectData.solutionExternalId;
}

projectData.type = CONSTANTS.common.IMPROVEMENT_PROJECT;
delete projectData.title;

if (projectData.certificate &&
projectData.certificate.osid &&
projectData.certificate.osid !== "" &&
projectData.certificate.templateUrl &&
projectData.certificate.templateUrl !== ""
) {
templateFilePath.push(projectData.certificate.templateUrl);
}

});

if( templateFilePath.length > 0 ) {

let certificateTemplateDownloadableUrl =
await coreService.getDownloadableUrl(
{
filePaths: templateFilePath
}
);
if ( !certificateTemplateDownloadableUrl.success ) {
throw {
message: CONSTANTS.apiResponses.DOWNLOADABLE_URL_NOT_FOUND
};
}
// map downloadable templateUrl to corresponding project data
data.forEach(projectData => {
if (projectData.certificate) {
var itemFromUrlArray = certificateTemplateDownloadableUrl.data.find(item=> item.filePath == projectData.certificate.templateUrl);
if (itemFromUrlArray) {
projectData.certificate.templateUrl = itemFromUrlArray.url;
}
}
if( projects.success && projects.data && projects.data.data && Object.keys(projects.data.data).length > 0 ) {

totalCount = projects.data.count;
data = projects.data.data;

if( data.length > 0 ) {
data.forEach( projectData => {
projectData.name = projectData.title;


if (projectData.programInformation) {
projectData.programName = projectData.programInformation.name;
delete projectData.programInformation;
}

)

if (projectData.solutionExternalId) {
projectData.externalId = projectData.solutionExternalId;
delete projectData.solutionExternalId;
}

projectData.type = CONSTANTS.common.IMPROVEMENT_PROJECT;
delete projectData.title;
});
}

}

return resolve({
success : true,
message : CONSTANTS.apiResponses.USER_ASSIGNED_PROJECT_FETCHED,
data : {
data: data,
count: totalCount
}
});

} catch (error) {
return resolve({
success : false,
message : error.message,
status :
error.status ?
error.status : HTTP_STATUS_CODE['internal_server_error'].status,
data : {
description : CONSTANTS.common.PROJECT_DESCRIPTION,
data : [],
count : 0
}
});
}

return resolve({
success : true,
message : CONSTANTS.apiResponses.USER_ASSIGNED_PROJECT_FETCHED,
data : {
data: data,
count: totalCount
}
});

} catch (error) {
return resolve({
success : false,
message : error.message,
status :
error.status ?
error.status : HTTP_STATUS_CODE['internal_server_error'].status,
data : {
description : CONSTANTS.common.PROJECT_DESCRIPTION,
data : [],
count : 0
}
});
}
})
}
})
}

/**
* List of user imported projects.
Expand Down Expand Up @@ -2685,7 +2646,7 @@ module.exports = class UserProjectsHelper {
* @returns {JSON} certificate data updation details.
*/

static certificates(userId) {
static certificates(userId) {
return new Promise(async (resolve, reject) => {
try {

Expand Down Expand Up @@ -2713,40 +2674,6 @@ module.exports = class UserProjectsHelper {
message: CONSTANTS.apiResponses.PROJECT_WITH_CERTIFICATE_NOT_FOUND
}
}
let templateFilePath = [];
//loop through user projects and get downloadable url for templateUrl if osid is present.
for( let userProjectPointer = 0; userProjectPointer < userProject.length; userProjectPointer++ ) {
if ( userProject[userProjectPointer].certificate.osid &&
userProject[userProjectPointer].certificate.osid !== "" &&
userProject[userProjectPointer].certificate.templateUrl &&
userProject[userProjectPointer].certificate.templateUrl !== ""
) {
templateFilePath.push(userProject[userProjectPointer].certificate.templateUrl);
}
}

if( templateFilePath.length > 0 ) {

let certificateTemplateDownloadableUrl =
await coreService.getDownloadableUrl(
{
filePaths: templateFilePath
}
);
if ( !certificateTemplateDownloadableUrl.success ) {
throw {
message: CONSTANTS.apiResponses.DOWNLOADABLE_URL_NOT_FOUND
};
}
// map downloadable templateUrl to corresponding project data
userProject.forEach(projectData => {
var itemFromUrlArray = certificateTemplateDownloadableUrl.data.find(item=> item.filePath == projectData.certificate.templateUrl);
if (itemFromUrlArray) {
projectData.certificate.templateUrl = itemFromUrlArray.url;
}
}
)
}

let count = _.countBy(userProject, (rec) => {
return (rec.certificate && rec.certificate.osid && rec.certificate.osid !== "" )? 'generated': 'notGenerated';
Expand Down Expand Up @@ -2780,7 +2707,7 @@ module.exports = class UserProjectsHelper {
* @returns {JSON} certificate re-issued details.
*/

static certificateReIssue(projectId) {
static certificateReIssue(projectId) {
return new Promise(async (resolve, reject) => {
try {
// get project details project for which certificate re-issue required .
Expand Down