Skip to content

Commit

Permalink
Merge branch 'release-7.0.0' into master-new
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhambansaltarento committed Jul 3, 2024
2 parents 469f2cd + fd0b7dc commit 19a7c0f
Show file tree
Hide file tree
Showing 12 changed files with 14,339 additions and 130 deletions.
13,748 changes: 13,748 additions & 0 deletions api-tests/Collections/Sunbird CoKreat API(s).postman_collection.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/envVariables.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const envVariables = {
SUNBIRD_KAFKA_BULKUPLOAD_CONSUMER_GROUP_ID:process.env.sunbird_kafka_bulkupload_consumer_group_id,
SUNBIRD_ASSESSMENT_SERVICE_BASE_URL : process.env.sunbird_assessment_service_base_url,
CORE_INGRESS_GATEWAY_IP: process.env.CORE_INGRESS_GATEWAY_IP,
COKREAT_USER_DELETE_KAFKA_TOPIC: process.env.cokreat_user_delete_kafka_topic || 'sunbirddev.delete.user',
config: {
user: process.env.sunbird_program_db_user || "postgres",
host: process.env.sunbird_program_db_host || "localhost",
Expand Down
132 changes: 86 additions & 46 deletions src/helpers/programHelper.js

Large diffs are not rendered by default.

50 changes: 43 additions & 7 deletions src/helpers/responseUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ const logger = require('sb_logger_util_v2');
const uuid = require("uuid/v1");
const stackTrace_MaxLimit = 500;
const _ = require('lodash');
const messageUtils = require('../service/messageUtil');
const responseCode = messageUtils.RESPONSE_CODE;
const loggerService = require('../service/loggerService');


const successResponse = (data) => {
Expand All @@ -10,21 +13,52 @@ const successResponse = (data) => {
response.ver = data.apiVersion
response.ts = new Date()
response.params = getParams(data.msgid, data.resmsgid, 'successful', null, null)
response.responseCode = data.responseCode || 'OK'
response.result = data.result
response.responseCode = data.responseCode || responseCode.SUCCESS
response.result = data.result || {}
return response
}

const errorResponse = (data,errCode) => {
const errorResponse = (data) => {
var response = {}
response.id = data.apiId
response.ver = data.apiVersion
response.ts = new Date()
response.params = getParams(data.msgid, data.resmsgid, 'failed', data.errCode, data.errMsg)
response.responseCode = errCode+'_'+data.responseCode
response.result = data.result
response.responseCode = data.responseCode
response.result = data.result || {};
return response
}

const responseObject = (data) => {
var response = {}
const responseStatus = (data.errCode) ? 'failed' : 'successfull'
const errorCode = data.errCode || null
const errMsg = data.errMsg || null
response.id = data.apiId
response.ver = data.apiVersion
response.ts = new Date()
response.params = getParams(data.msgid, data.resmsgid, responseStatus, errorCode, errMsg)
response.responseCode = data.responseCode
response.result = data.result || {};
return response
}
const handleSuccessResponse = (req, response, logObject) => {
var rspObj = req.rspObj
loggerService.exitLog({responseCode: rspObj.responseCode}, logObject);
return response.status(200).send(responseObject(rspObj));
}

const handleErrorResponse = (req, response, logObject, error) => {
var rspObj = req.rspObj
console.log(`${rspObj.apiId}`, JSON.stringify(error))
if(error && error.response && error.response.data) {
console.log(`${rspObj.apiId}`, JSON.stringify(error.response.data));
}
const statusCode = rspObj.statusCode || 500;
rspObj.responseCode = rspObj.responseCode || responseCode.SERVER_ERROR;
loggerError(rspObj, rspObj.errCode);
loggerService.exitLog({responseCode: rspObj.responseCode}, logObject);
return response.status(statusCode).send(responseObject(rspObj));
}

const getParams = (msgId = null, resmsgId = null, status, errCode, msg) => {
var params = {}
Expand Down Expand Up @@ -52,5 +86,7 @@ module.exports = {
successResponse,
errorResponse,
getParams,
loggerError
loggerError,
handleSuccessResponse,
handleErrorResponse
}
3 changes: 3 additions & 0 deletions src/helpers/updateHierarchy.helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class HierarchyService {
}

createCollection(collections, reqHeaders) {
// loggerService.debugLog("createCollection() - ");
const url = `${envVariables.CONTENT_SERVICE_URL}content/v4/create`;

const bulkRequest = _.map(collections, collection => {
Expand Down Expand Up @@ -119,6 +120,7 @@ class HierarchyService {
identifier: collection.result.content.identifier
}
};
// loggerService.debugLog({"CreateCollection data ": option});
return axios(option);
});
return forkJoin(...bulkRequest);
Expand Down Expand Up @@ -184,6 +186,7 @@ class HierarchyService {
}

newHierarchyUpdateRequest(collection, additionalMetaData, children) {
// loggerService.debugLog("newHierarchyUpdateRequest() - ");
let instance = this;
this.hierarchy = {};
this.nodeModified = {};
Expand Down
3 changes: 0 additions & 3 deletions src/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ fs.readdirSync(__dirname)
});

db.sequelize = sequelize;
db.Sequelize = Sequelize;

db.program.hasMany(db.nomination, {foreignKey: 'program_id'});
db.nomination.belongsTo(db.program, {foreignKey: 'program_id'});

HelperService.AttachModelHooks(db);

module.exports = db;
6 changes: 6 additions & 0 deletions src/routes/programRoutes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const programService = require('../service/programService');
const userProgramPreference = require('../service/userProgramPreference');
const formConfig = require('../service/formConfig');
const userService = require('../service/userService');

const requestMiddleware = require('../middlewares/request.middleware')

const BASE_URL = '/program/v1'
Expand Down Expand Up @@ -133,4 +135,8 @@ module.exports = function (app) {
app.route(BASE_URL + '/form/read')
.post(requestMiddleware.gzipCompression(), requestMiddleware.createAndValidateRequestBody,
formConfig.getForm)

app.route(BASE_URL + '/user/:userId')
.delete(requestMiddleware.createAndValidateRequestBody,
userService.deleteUser)
}
15 changes: 15 additions & 0 deletions src/service/loggerService.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ function exitLog(data, logObject) {
return log;
}

function debugLog(logObject){
const log = {
"eid": "LOG",
"edata": {
"type": "system",
"level": "TRACE",
"message": JSON.stringify(logObject),
}
}
logger.debug({ msg: 'Debug info', log});
return log;

}

module.exports.logFormate = logFormate;
module.exports.entryLog = entryLog;
module.exports.exitLog = exitLog;
module.exports.debugLog = debugLog;
20 changes: 15 additions & 5 deletions src/service/messageUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,10 +514,9 @@ exports.EMAIL = {
}

exports.HEALTH_CHECK = {
EK_STEP: {
NAME: 'ekstep.api',
FAILED_CODE: 'CONTENT_PROVIDER_HEALTH_FAILED',
FAILED_MESSAGE: 'Content provider service is not healthy'
POSTGRES_DB: {
FAILED_CODE: 'POSTGRES_HEALTH_FAILED',
FAILED_MESSAGE: 'Postgres db is not connected'
},
LEARNER_SERVICE: {
NAME: 'learnerservice.api',
Expand All @@ -539,7 +538,6 @@ exports.DIALCODE = {
FAILED_MESSAGE: 'Generate dialcode failed',
MISSING_COUNT: 'ERR_DIALCODE_GENERATE_COUNT_ERROR',
MISSING_COUNT_MESSAGE: 'Required fields count is missing or invalid'

},

LIST: {
Expand Down Expand Up @@ -1011,3 +1009,15 @@ exports.PROGRAM_FEED = {
INFO: 'Search For Program Feed Updates'
}
}

exports.USER = {
DELETE: {
FAILED_CODE: "ERR_DELETING_USER_FAILED",
MISSING_CODE: 'ERR_DELETING_USER_MISSING',
MISSING_MESSAGE: "User id is not passed in the request",
FAILED_MESSAGE: 'Unable to delete given user',
EXCEPTION_CODE: 'USER_DEL',
INFO: 'Delete User'
}
}

4 changes: 2 additions & 2 deletions src/service/print/printDocxV1.0/dataImporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const fields =
"body,primaryCategory,mimeType,qType,answer,templateId,responseDeclaration,interactionTypes,interactions,name,solutions,editorState,media,name,board,medium,gradeLevel,subject,topic,learningOutcome,maxScore,bloomsLevel,author,copyright,license,instructions";

const QUE_READ_URL= `${envVariables.SUNBIRD_ASSESSMENT_SERVICE_BASE_URL}/question/v4/read/`;
const QS_HIERARCHY_READ_URL = `${envVariables.SUNBIRD_ASSESSMENT_SERVICE_BASE_URL}/questionset/v4/hierarchy/`;
const QS_HIERARCHY_READ_URL = `${envVariables.SUNBIRD_ASSESSMENT_SERVICE_BASE_URL}/questionset/v5/hierarchy/`;


const getQuestionForSet = async (id) => {
Expand Down Expand Up @@ -47,7 +47,7 @@ const getQuestionSet = async (config) => {
};

return axios(request).then(async (r) => {
const data = r.data.result.questionSet;
const data = r.data.result.questionset;
let sections;
if (data && "children" in data) sections = data.children;
else {
Expand Down
Loading

0 comments on commit 19a7c0f

Please sign in to comment.