Skip to content

Commit

Permalink
Merge pull request #77 from shikshalokam/SB-29009
Browse files Browse the repository at this point in the history
SB-29009 resolve for 4.7
  • Loading branch information
aks30 authored Mar 9, 2022
2 parents 4b788b0 + 32922e4 commit aeb1a03
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 0 deletions.
15 changes: 15 additions & 0 deletions controllers/v1/programs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* name : programs.js
* author : vishnu
* created-date : 09-Mar-2022
* Description : programs related information.
*/
module.exports = class Programs extends Abstract{
constructor() {
super("programs");
}

static get name() {
return "programs";
}
}
62 changes: 62 additions & 0 deletions databaseQueries/programs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* name : programs.js
* author : Vishnu
* created-date : 09-Mar-2022
* Description : program helper for DB interactions.
*/

// Dependencies

/**
* Programs
* @class
*/



module.exports= class Programs{
/**
* programs details.
* @method
* @name programsDocument
* @param {Array} [filterData = "all"] - programs filter query.
* @param {Array} [fieldsArray = "all"] - projected fields.
* @param {Array} [skipFields = "none"] - field not to include
* @returns {Array} program details.
*/

static programsDocument(
filterData = "all",
fieldsArray = "all",
skipFields = "none"
) {
return new Promise(async (resolve, reject) => {
try {
let queryObject = (filterData != "all") ? filterData : {};
let projection = {}

if (fieldsArray != "all") {
fieldsArray.forEach(field => {
projection[field] = 1;
});
}

if( skipFields !== "none" ) {
skipFields.forEach(field=>{
projection[field] = 0;
});
}
let programsDoc =
await database.models.programs.find(
queryObject,
projection
).lean();

return resolve(programsDoc);

} catch (error) {
return reject(error);
}
});
}
}
52 changes: 52 additions & 0 deletions models/programs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* name : programs-model.js.
* author : Vishnu.
* created-date : 09-Mar-2022.
* Description : Schema for programs.
*/
module.exports = {
name: "programs",
schema: {
externalId: String,
name: String,
description: String,
owner: String,
createdBy: String,
updatedBy: String,
status: {
type : String,
index : true
},
resourceType: [String],
language: [String],
keywords: [String],
concepts: ["json"],
imageCompression: {},
components: ["json"],
components: ["json"],
isAPrivateProgram : {
default : false,
type : Boolean
},
scope : {
entityType : String,
entityTypeId : "ObjectId",
entities : {
type : Array,
index : true
},
roles : [{
_id : "ObjectId",
code : {
type : String,
index : true
}
}]
},
isDeleted: {
default : false,
type : Boolean,
index : true
}
}
};
25 changes: 25 additions & 0 deletions module/userProjects/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ const projectQueries = require(DB_QUERY_BASE_PATH + "/projects");
const projectCategoriesQueries = require(DB_QUERY_BASE_PATH + "/projectCategories");
const projectTemplateQueries = require(DB_QUERY_BASE_PATH + "/projectTemplates");
const projectTemplateTaskQueries = require(DB_QUERY_BASE_PATH + "/projectTemplateTask");

const programsQueries = require(DB_QUERY_BASE_PATH + "/programs");

const kafkaProducersHelper = require(GENERICS_FILES_PATH + "/kafka/producers");
const removeFieldsFromRequest = ["submissionDetails"];

Expand Down Expand Up @@ -1398,7 +1401,29 @@ module.exports = class UserProjectsHelper {

createProject =
_.merge(createProject, programAndSolutionInformation.data);
}else {
let queryData = {};
queryData["_id"] = data.programId;
let programDetails = await programsQueries.programsDocument(queryData,
[
"_id",
"name",
"description",
"isAPrivateProgram"
]
);
if( !programDetails.length > 0 ){
throw {
status: HTTP_STATUS_CODE['bad_request'].status,
message: CONSTANTS.apiResponses.PROGRAM_NOT_FOUND
};
}
let programInformationData = {};
programInformationData["programInformation"] = programDetails[0];
createProject =
_.merge(createProject, programInformationData);
}


if (data.tasks) {

Expand Down

0 comments on commit aeb1a03

Please sign in to comment.