Skip to content

Commit

Permalink
Merge pull request #278 from YujithIsura/master
Browse files Browse the repository at this point in the history
New endpoint added for getting pending nomination for notification module
  • Loading branch information
YujithIsura authored Mar 6, 2020
2 parents a4ff8b1 + 9427a0c commit 647b3e4
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 8 deletions.
30 changes: 27 additions & 3 deletions server/src/manager/nomination/nominationManager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Nomination } from 'Models';
import { Nomination,NominationNotification } from 'Models';
var joinjs = require('join-js').default;
import {List} from 'typed-immutable';
import _ from 'lodash';
Expand All @@ -16,13 +16,18 @@ const resultMaps = [
mapId: 'candidateMap',
idProperty: 'id',
properties: ['name','nic','occupation','address']
},
},
{
mapId: 'nominationNotificationMap',
idProperty: 'id',
properties: ['party', 'division_name','payment_status', 'objection_status','objection_status','approval_status','review_note']
},
];


const mapToNominationModel = (nominationData) => {
const mappedNominations = joinjs.map(nominationData, resultMaps, 'nominationMap', 'nomination_');
return _.reduce(mappedNominations, function(result, nomination) {
console.log("mappedNominations",nomination.Candidates);
return result.push({
id: nomination.id,
division_name: nomination.division_name,
Expand All @@ -36,6 +41,25 @@ const mapToNominationModel = (nominationData) => {
},List(Nomination)());
};

const mapToNominationNotificationModel = (nominationData) => {
const mappedNominations = joinjs.map(nominationData, resultMaps, 'nominationNotificationMap', 'nomination_');

return _.reduce(mappedNominations, function(result, nomination) {
return result.push({
id: nomination.id,
division_name: nomination.division_name,
party: nomination.party,
payment_status: nomination.payment_status,
objection_status: nomination.objection_status,
approval_status: nomination.approval_status,
reviewNote: nomination.review_note
});
},List(NominationNotification)());
};



export default {
mapToNominationModel,
mapToNominationNotificationModel
};
13 changes: 12 additions & 1 deletion server/src/model/Nomination.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ const Nomination = Record({
reviewNote: Maybe(String)
});

const NominationNotification = Record({
id: String(),
division_name: String(),
party: Maybe(String),
payment_status: Maybe(String),
objection_status: Maybe(String),
approval_status: Maybe(String),
reviewNote: Maybe(String)
});

export {
Nomination
Nomination,
NominationNotification
}
5 changes: 3 additions & 2 deletions server/src/model/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Team } from './Team';
import { Candidate } from './Candidate';
import { Payment , NominationPayment,AllPayments } from './Payment';
import { Election, AllElection, ElectionWithStatus } from './Election';
import { Nomination } from './Nomination';
import { Nomination,NominationNotification } from './Nomination';
import { Division, AllowedDivision } from './Division';
import { SupportDoc,CandidateSupportDoc,CandidateSupportDocData } from './SupportDoc';
import {Module,ModuleList,AllElectionTemplate,CandidateConfig} from './Module';
Expand Down Expand Up @@ -38,5 +38,6 @@ export {
AllPayments,
electoratesData,
eligibilityData,
CandidateConfig
CandidateConfig,
NominationNotification
};
55 changes: 54 additions & 1 deletion server/src/repository/nomination.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ const PENDING_NOMINATION_SELECT_QUERY_ALL_TEAM = `SELECT
LEFT JOIN NOMINATION_APPROVAL NA ON N.ID = NA.NOMINATION_ID
WHERE ELECTION_ID=:electionId
AND N.STATUS=:status AND N.DIVISION_CONFIG_ID=:divisionId`;

const PENDING_NOMINATION_SELECT_QUERY_ALL_TEAM_FOR_NOTIFICATION = `SELECT
N.ID AS nomination_id,
DC.NAME AS nomination_division_name,
N.TEAM_ID AS nomination_party,
P.STATUS AS nomination_payment_status,
OBR.STATUS AS nomination_objection_status,
NA.STATUS AS nomination_approval_status,
NA.REVIEW_NOTE AS nomination_review_note
FROM NOMINATION N LEFT JOIN DIVISION_CONFIG DC ON N.DIVISION_CONFIG_ID = DC.ID
LEFT JOIN PAYMENT P ON N.ID = P.NOMINATION_ID
LEFT JOIN OBJECTION O ON N.ID = O.NOMINATION_ID
LEFT JOIN OBJECTION_REVIEW OBR ON O.ID = OBR.OBJECTION_ID
LEFT JOIN NOMINATION_APPROVAL NA ON N.ID = NA.NOMINATION_ID
WHERE N.STATUS=:status AND N.DIVISION_CONFIG_ID=:divisionId`;
const PENDING_NOMINATION_SELECT_QUERY_ALL_TEAM_ALL_DIVISION = `SELECT
N.ID AS nomination_id,
DC.NAME AS nomination_division_name,
Expand All @@ -60,6 +75,21 @@ const PENDING_NOMINATION_SELECT_QUERY_ALL_TEAM_ALL_DIVISION = `SELECT
LEFT JOIN NOMINATION_APPROVAL NA ON N.ID = NA.NOMINATION_ID
WHERE ELECTION_ID=:electionId
AND N.STATUS=:status`;

const PENDING_NOMINATION_SELECT_QUERY_ALL_TEAM_ALL_DIVISION_FOR_NOTIFICATION = `SELECT
N.ID AS nomination_id,
DC.NAME AS nomination_division_name,
N.TEAM_ID AS nomination_party,
P.STATUS AS nomination_payment_status,
OBR.STATUS AS nomination_objection_status,
NA.STATUS AS nomination_approval_status,
NA.REVIEW_NOTE AS nomination_review_note
FROM NOMINATION N LEFT JOIN DIVISION_CONFIG DC ON N.DIVISION_CONFIG_ID = DC.ID
LEFT JOIN PAYMENT P ON N.ID = P.NOMINATION_ID
LEFT JOIN OBJECTION O ON N.ID = O.NOMINATION_ID
LEFT JOIN OBJECTION_REVIEW OBR ON O.ID = OBR.OBJECTION_ID
LEFT JOIN NOMINATION_APPROVAL NA ON N.ID = NA.NOMINATION_ID
WHERE N.STATUS=:status`;

const PENDING_NOMINATION_SELECT_QUERY = `SELECT
N.ID AS nomination_id,
Expand Down Expand Up @@ -222,6 +252,28 @@ const fetchPendingNominationList = (params) => {

}

const fetchPendingNominationListForNotification = (params) => {
if(params.divisionId === 'all'){
return DbConnection()
.query(PENDING_NOMINATION_SELECT_QUERY_ALL_TEAM_ALL_DIVISION_FOR_NOTIFICATION,
{
replacements: params,
type: DbConnection().QueryTypes.SELECT,
}).catch((error) => {
throw new DBError(error);
});
}else{
return DbConnection()
.query(PENDING_NOMINATION_SELECT_QUERY_ALL_TEAM_FOR_NOTIFICATION,
{
replacements: params,
type: DbConnection().QueryTypes.SELECT,
}).catch((error) => {
throw new DBError(error);
});
}
}

const fetchNominationPaymentStatus = (params) => {

return DbConnection()
Expand Down Expand Up @@ -279,5 +331,6 @@ export default {
fetchPendingNominationList,
createNominationStatus,
fetchNominationPaymentStatus,
fetchNominationData
fetchNominationData,
fetchPendingNominationListForNotification
}
9 changes: 9 additions & 0 deletions server/src/routes/nominationRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,15 @@ export const initNominationRouter = (app) => {
.catch(error => next(error));
},
},
{
method: GET,
path: '/nominations/:status/divisions/:divisionId',
handler: (req, res, next) => {
return NominationService.getPendingNominationsByStatus(req)
.then((result) => res.status(HTTP_CODE_200).send(result))
.catch(error => next(error));
},
},
{
method: POST,
path: '/nominations/:nominationId/approve-nomination',
Expand Down
25 changes: 24 additions & 1 deletion server/src/service/nominationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,28 @@ const getPendingNominationsByElectionId = async (req) => {
}
};

//Get second approve pending nomination list for notification
const getPendingNominationsByStatus = async (req) => {
try {
const electionId = req.params.electionId;
const status = req.params.status;
const divisionId = req.params.divisionId;

const params = {'electionId':electionId, "status":status,"divisionId":divisionId }
const nominations = await NominationRepo.fetchPendingNominationListForNotification( params );

if(!_.isEmpty(nominations)){
return NominationManager.mapToNominationNotificationModel(nominations)
}else {
// throw new ApiError("Nominations not found", HTTP_CODE_204);
return [];
}
} catch (e){
console.log(e);
throw new ServerError("Server error", HTTP_CODE_404);
}
};

//approve nomination by nomination id
const saveApproveNominationByNominationId = async (req) => {
try {
Expand Down Expand Up @@ -146,5 +168,6 @@ export default {
getPendingNominationsByElectionId,
saveApproveNominationByNominationId,
getNominationPaymentStatusByElectionId,
getNominationDataByNominationId
getNominationDataByNominationId,
getPendingNominationsByStatus
};

0 comments on commit 647b3e4

Please sign in to comment.