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

program Targetting #90

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
92 changes: 91 additions & 1 deletion controllers/v1/forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
return "forms";
}

/**
/**
* @api {get} /kendra/api/v1/forms/details/:formName
* Form details
* @apiVersion 0.0.1
Expand Down Expand Up @@ -102,5 +102,95 @@
});
}

/**
* @api {post} /kendra/api/v1/forms/create
* Form Create
* @apiVersion 0.0.1
* @apiName Form Create
* @apiGroup Forms
* @apiHeader {String} X-authenticated-user-token Authenticity token
* @apiSampleRequest /kendra/api/v1/forms/create
* @apiUse successBody
* @apiUse errorBody
* @apiParamExample {json} Response:
* {
* "status": 200,
"message": "Forms created successfully",
"result": {
"_id": "5f33c3d85f637784791cd830"
}
}
*/

/**
* Create form.
* @method
* @name create
* @param {Object} req - Requested data.
* @returns {JSON} Form details.
*/

async create(req) {
return new Promise(async (resolve, reject) => {
try {

let createForm = await formsHelper.create(req.body);
return resolve(createForm);

} catch (error) {
return reject({
status: error.status || httpStatusCode.internal_server_error.status,
message: error.message || httpStatusCode.internal_server_error.message,
errorObject: error
});
}
});
}

/**
* @api {post} /kendra/api/v1/forms/update/scope
* Form Update
* @apiVersion 0.0.1
* @apiName Form Update
* @apiGroup Forms
* @apiHeader {String} X-authenticated-user-token Authenticity token
* @apiSampleRequest /kendra/api/v1/forms/update/scope
* @apiUse successBody
* @apiUse errorBody
* @apiParamExample {json} Response:
* {
* "status": 200,
"message": "Forms updated successfully"
}
*/

/**
* Update form.
* @method
* @name update
* @param {Object} req - Requested data.
* @param {Object} req.params._id - Form name.
* @returns {JSON} Form details.
*/

async update(req) {
return new Promise(async (resolve, reject) => {
try {

let updateForm = await formsHelper.update(
req.params._id,
req.body
);
return resolve(updateForm);

} catch (error) {
return reject({
status: error.status || httpStatusCode.internal_server_error.status,
message: error.message || httpStatusCode.internal_server_error.message,
errorObject: error
});
}
});
}
};

73 changes: 49 additions & 24 deletions controllers/v1/solutions.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,13 @@ module.exports = class Solutions extends Abstract {
* @apiGroup Solutions
* @apiParamExample {json} Request-Body:
* {
"role" : "HM,DEO",
"state" : "236f5cff-c9af-4366-b0b6-253a1789766a",
"district" : "1dcbc362-ec4c-4559-9081-e0c2864c2931",
"school" : "c5726207-4f9f-4f45-91f1-3e9e8e84d824",
"roles" : "HM,DEO",
"entities": {
"block": "81ca90fa-e38b-4d5d-858a-20ae5b402438",
"district": "b5c35cfc-6c1e-4266-94ef-a425c43c7f4e",
"state": "bc75cc99-9205-463e-a722-5326857838f8",
"school": "28236605304"
},
"filter" : {}
}
* @apiHeader {String} X-authenticated-user-token Authenticity token
Expand Down Expand Up @@ -255,7 +258,10 @@ module.exports = class Solutions extends Abstract {
req.query.programId ? req.query.programId : "",
req.pageSize,
req.pageNo,
req.searchText
req.searchText,
req.headers["x-app-ver"] ? req.headers["x-app-ver"] : req.headers.appversion ? req.headers.appversion : "",
req.userDetails.userId,
req.userDetails.userToken
);

targetedSolutions["result"] = targetedSolutions.data;
Expand All @@ -278,10 +284,13 @@ module.exports = class Solutions extends Abstract {
* @apiGroup Solutions
* @apiParamExample {json} Request-Body:
* {
"role" : "HM,DEO",
"state" : "236f5cff-c9af-4366-b0b6-253a1789766a",
"district" : "1dcbc362-ec4c-4559-9081-e0c2864c2931",
"school" : "c5726207-4f9f-4f45-91f1-3e9e8e84d824"
"roles" : "HM,DEO",
"entities": {
"block": "81ca90fa-e38b-4d5d-858a-20ae5b402438",
"district": "b5c35cfc-6c1e-4266-94ef-a425c43c7f4e",
"state": "bc75cc99-9205-463e-a722-5326857838f8",
"school": "28236605304"
}
}
* @apiHeader {String} X-authenticated-user-token Authenticity token
* @apiSampleRequest /kendra/api/v1/solutions/detailsBasedOnRoleAndLocation/5fc3dff14ea9b44f3340afe2
Expand Down Expand Up @@ -320,7 +329,10 @@ module.exports = class Solutions extends Abstract {
let solutionDetails =
await solutionsHelper.detailsBasedOnRoleAndLocation(
req.params._id,
req.body
req.body,
req.headers["x-app-ver"] ? req.headers["x-app-ver"] : req.headers.appversion ? req.headers.appversion : "",
req.userDetails.userId,
req.userDetails.userToken
);

solutionDetails.result = solutionDetails.data;
Expand Down Expand Up @@ -680,10 +692,13 @@ module.exports = class Solutions extends Abstract {
* @apiSampleRequest /kendra/api/v1/solutions/targetedSolutions?type=observation&page=1&limit=10&search=a&filter=assignedToMe
* @apiParamExample {json} Request:
* {
* "role" : "HM,DEO",
"state" : "236f5cff-c9af-4366-b0b6-253a1789766a",
"district" : "1dcbc362-ec4c-4559-9081-e0c2864c2931",
"school" : "c5726207-4f9f-4f45-91f1-3e9e8e84d824"
"entities": {
"block": "81ca90fa-e38b-4d5d-858a-20ae5b402438",
"district": "b5c35cfc-6c1e-4266-94ef-a425c43c7f4e",
"state": "bc75cc99-9205-463e-a722-5326857838f8",
"school": "28236605304"
},
"roles": "DEO,HM"
}
* @apiParamExample {json} Response:
{
Expand Down Expand Up @@ -732,7 +747,10 @@ module.exports = class Solutions extends Abstract {
req.pageNo,
req.searchText,
req.query.filter,
req.query.surveyReportPage ? req.query.surveyReportPage : ""
req.query.surveyReportPage ? req.query.surveyReportPage : "",
req.headers["x-app-ver"] ? req.headers["x-app-ver"] : req.headers.appversion ? req.headers.appversion : "",
req.userDetails.userId

);

observations["result"] = observations.data;
Expand Down Expand Up @@ -808,10 +826,13 @@ module.exports = class Solutions extends Abstract {
* @apiUse errorBody
* @apiParamExample {json} Request:
* {
* "role" : "HM,DEO",
"state" : "236f5cff-c9af-4366-b0b6-253a1789766a",
"district" : "1dcbc362-ec4c-4559-9081-e0c2864c2931",
"school" : "c5726207-4f9f-4f45-91f1-3e9e8e84d824"
"entities": {
"block": "81ca90fa-e38b-4d5d-858a-20ae5b402438",
"district": "b5c35cfc-6c1e-4266-94ef-a425c43c7f4e",
"state": "bc75cc99-9205-463e-a722-5326857838f8",
"school": "28236605304"
},
"roles": "DEO,HM"
}
* @apiParamExample {json} Response:
* {
Expand Down Expand Up @@ -846,7 +867,8 @@ module.exports = class Solutions extends Abstract {
req.body,
req.userDetails.userId,
req.userDetails.userToken,
req.query.hasOwnProperty("createProject") ? gen.utils.convertStringToBoolean(req.query.createProject) : true
req.query.hasOwnProperty("createProject") ? gen.utils.convertStringToBoolean(req.query.createProject) : true,
req.headers["x-app-ver"] ? req.headers["x-app-ver"] : req.headers.appversion ? req.headers.appversion : ""
);

return resolve(solutionData);
Expand All @@ -873,10 +895,13 @@ module.exports = class Solutions extends Abstract {
* @apiUse errorBody
* @apiParamExample {json} Request:
* {
* "role" : "HM,DEO",
"state" : "236f5cff-c9af-4366-b0b6-253a1789766a",
"district" : "1dcbc362-ec4c-4559-9081-e0c2864c2931",
"school" : "c5726207-4f9f-4f45-91f1-3e9e8e84d824"
"entities": {
"block": "81ca90fa-e38b-4d5d-858a-20ae5b402438",
"district": "b5c35cfc-6c1e-4266-94ef-a425c43c7f4e",
"state": "bc75cc99-9205-463e-a722-5326857838f8",
"school": "28236605304"
},
"roles": "DEO,HM"
}
* @apiParamExample {json} Response:
* {
Expand Down
84 changes: 52 additions & 32 deletions controllers/v1/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/

const usersHelper = require(MODULES_BASE_PATH + "/users/helper.js");
const solutionsHelper = require(MODULES_BASE_PATH + "/solutions/helper.js");

/**
* User
Expand Down Expand Up @@ -218,10 +219,12 @@ module.exports = class Users extends Abstract {
* @apiSampleRequest /kendra/api/v1/users/solutions/5ff438b04698083dbfab7284?page=1&limit=10
* @apiParamExample {json} Request-Body:
* {
"role" : "HM,DEO",
"state" : "236f5cff-c9af-4366-b0b6-253a1789766a",
"district" : "1dcbc362-ec4c-4559-9081-e0c2864c2931",
"school" : "c5726207-4f9f-4f45-91f1-3e9e8e84d824"
"roles" : "HM,DEO",
"entities": {
"state" : "236f5cff-c9af-4366-b0b6-253a1789766a",
"district" : "1dcbc362-ec4c-4559-9081-e0c2864c2931",
"school" : "c5726207-4f9f-4f45-91f1-3e9e8e84d824"
}
}
* @apiUse successBody
* @apiUse errorBody
Expand Down Expand Up @@ -277,14 +280,15 @@ module.exports = class Users extends Abstract {
req.pageSize,
req.pageNo,
req.searchText,
req.headers["x-app-ver"] ? req.headers["x-app-ver"] : req.headers.appversion ? req.headers.appversion : "",
req.userDetails.userId,
req.userDetails.userToken
);

targetedSolutions["result"] = targetedSolutions.data;
return resolve(targetedSolutions);

} catch (error) {

return reject({
status:
error.status ||
Expand All @@ -310,11 +314,13 @@ module.exports = class Users extends Abstract {
* @apiUse errorBody
* @apiParamExample {json} Request:
* {
"role" : "HM,DEO",
"state" : "236f5cff-c9af-4366-b0b6-253a1789766a",
"district" : "1dcbc362-ec4c-4559-9081-e0c2864c2931",
"school" : "c5726207-4f9f-4f45-91f1-3e9e8e84d824"
}
"roles" : "HM,DEO",
"entities": {
"state" : "236f5cff-c9af-4366-b0b6-253a1789766a",
"district" : "1dcbc362-ec4c-4559-9081-e0c2864c2931",
"school" : "c5726207-4f9f-4f45-91f1-3e9e8e84d824"
}
}
* @apiParamExample {json} Response:
* {
* "message": "Users programs fetched successfully",
Expand Down Expand Up @@ -351,35 +357,36 @@ module.exports = class Users extends Abstract {

try {

let isAPrivateProgram = gen.utils.convertStringToBoolean(req.query.isAPrivateProgram);
let isAPrivateProgram = gen.utils.convertStringToBoolean(req.query.isAPrivateProgram);

if(isAPrivateProgram){
if ( isAPrivateProgram ) {

let programsData = await usersHelper.privatePrograms(req.userDetails.userId);
return resolve(programsData);
let programsData = await usersHelper.privatePrograms(req.userDetails.userId);
return resolve(programsData);

} else {
} else {

let programs =
await usersHelper.programs(
req.body,
req.pageNo,
req.pageSize,
req.searchText
);
let programs =
await usersHelper.programs(
req.body,
req.pageNo,
req.pageSize,
req.searchText,
req.headers["x-app-ver"] ? req.headers["x-app-ver"] : req.headers.appversion ? req.headers.appversion : "",
req.userDetails.userId,
req.userDetails.userToken
);

programs.result = programs.data;
return resolve(programs);
programs.result = programs.data;
return resolve(programs);

}
}

} catch (error) {

return reject({
status:
error.status ||
httpStatusCode["internal_server_error"].status,

message:
error.message ||
httpStatusCode["internal_server_error"].message
Expand Down Expand Up @@ -471,10 +478,12 @@ module.exports = class Users extends Abstract {
* @apiGroup Users
* @apiParamExample {json} Request-Body:
* {
"state" : "bc75cc99-9205-463e-a722-5326857838f8",
"district" : "b54a5c6d-98be-4313-af1c-33040b1703aa",
"school" : "2a128c91-a5a2-4e25-aa21-3d9196ad8203",
"role" : "DEO,HM"
"roles" : "HM,DEO",
"entities": {
"state" : "236f5cff-c9af-4366-b0b6-253a1789766a",
"district" : "1dcbc362-ec4c-4559-9081-e0c2864c2931",
"school" : "c5726207-4f9f-4f45-91f1-3e9e8e84d824"
}
}
* @apiHeader {String} X-authenticated-user-token Authenticity token
* @apiSampleRequest /kendra/api/v1/users/targetedEntity/601d41607d4c835cf8b724ad
Expand Down Expand Up @@ -504,7 +513,18 @@ module.exports = class Users extends Abstract {
return new Promise(async (resolve, reject) => {
try {

let roleArray = req.body.role.split(",");
let convertedBodyData = await solutionsHelper.checkForConvertBodyData(
req.body,
req.headers["x-app-ver"] ? req.headers["x-app-ver"] : req.headers.appversion ? req.headers.appversion : "",
req.userDetails.userId,
req.userDetails.userToken
);

if( convertedBodyData.success ) {
req.body = convertedBodyData.data
}

let roleArray = req.body.roles.split(",");
let targetedEntities = {};

if ( roleArray.length === 1 ) {
Expand Down
Loading