Skip to content
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
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@ coverage
*.iml
package-lock.json
.DS_Store
build/
build/




.bin
.vs
.obj

297 changes: 297 additions & 0 deletions Nomination.njsproj

Large diffs are not rendered by default.

Binary file added bin/Microsoft.NodejsTools.WebRole.dll
Binary file not shown.
1 change: 1 addition & 0 deletions obj/Debug/Nomination.njsproj.CoreCompileInputs.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
07e3dfdc747d235400f294e34b8edca0edec755d
Binary file not shown.
1 change: 1 addition & 0 deletions obj/Release/Nomination.njsproj.CoreCompileInputs.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
07e3dfdc747d235400f294e34b8edca0edec755d
35 changes: 35 additions & 0 deletions src/manager/approvedElection/ApprovedElectionManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { ApprovedElection } from 'Models';
import _ from "lodash";
import moment from "../candidate/candidateManager";
import {List} from "typed-immutable";
var joinjs = require('join-js').default;
// join-js usage : https://www.npmjs.com/package/join-js

const resultMaps = [
{
mapId: 'approvedElectionMap',
idProperty: 'ID',
properties: ['NAME', 'CREATED_BY', 'CREATED_AT','UPDATED_AT','MODULE_ID','STATUS','APPROVED_BY','APPROVED_AT']
}
];


const mapToApprovedElectionsDataModel = (activeApprovedElections) => {

// return activeApprovedElections;
const mappedActiveElections = joinjs.map(activeApprovedElections, resultMaps, 'approvedElectionMap', 'APPROVED_ELECTION_');
console.log(mappedActiveElections);

return _.reduce(mappedActiveElections, function(result, approvedElection) {
return result.push({

"name": approvedElection.NAME,


});
},List(ApprovedElection)())
};

export default {
mapToApprovedElectionsDataModel,
};
3 changes: 2 additions & 1 deletion src/manager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import ModuleManager from './module/moduleManager';
import ObjectionManager from './objection/objectionManager';
import ActiveElectionManager from './activeElection/activeElectionManager';
import ElectionNominationManager from './electionNomination/electionNominationManager';

import ApprovedElectionManager from './approvedElection/ApprovedElectionManager';
export {
UserManager,
PaymentManager,
Expand All @@ -24,4 +24,5 @@ export {
ObjectionManager,
ActiveElectionManager,
ElectionNominationManager,
ApprovedElectionManager,
}
8 changes: 8 additions & 0 deletions src/model/approvedElection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

import {Record} from 'typed-immutable';

export const Candidate = Record({

name:String(),

});
4 changes: 3 additions & 1 deletion src/model/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { SupportDoc,CandidateSupportDoc } from './SupportDoc';
import {Module} from './Module';
import {Objection } from './Objection';
import {ActiveElection } from './ActiveElection';
import {ElectionNomination} from './ElectionNomination'
import {ElectionNomination} from './ElectionNomination';
import {ApprovedElection} from './approvedElection';


export {
Expand All @@ -30,4 +31,5 @@ export {
ActiveElection,
ElectionNomination,
AllowedDivision,
ApprovedElection,
};
2 changes: 2 additions & 0 deletions src/repository/dataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ class DataSourceFactory {
throw new Error('Cannot construct singleton');
}


this.dbConnection = new Sequelize(configService.getConfig('DB_NAME'),configService.getConfig('DB_USER'), configService.getConfig('DB_PASSWORD'),
configService.getConfig('DB_USER'), {
host: configService.getConfig('DB_HOST')
});

}

/**
Expand Down
27 changes: 27 additions & 0 deletions src/repository/election.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,37 @@ const fetchElectionsByStatus = (status) => {
});
}

const APPROVED_ELECTION_SELECT_QUERY = `SELECT
E.ID AS APPROVED_ELECTION_ID,
E.NAME AS APPROVED_ELECTION_NAME,
E.CREATED_BY AS APPROVED_ELECTION_CREATED_BY,
E.CREATED_AT AS APPROVED_ELECTION_CREATED_AT,
E.UPDATED_AT AS APPROVED_ELECTION_UPDATED_AT,
E.MODULE_ID AS APPROVED_ELECTION_MODULE_ID,
EA.STATUS AS APPROVED_ELECTION_STATUS,
EA.APPROVED_BY AS APPROVED_ELECTION_APPROVED_BY,
EA.APPROVED_AT AS APPROVED_ELECTION_APPROVED_AT,
EA.UPDATED_AT AS APPROVED_ELECTION_UPDATED_AT
FROM ELECTION AS E
INNER JOIN election_approval AS EA
ON E.ID = EA.ELECTION_ID
WHERE EA.STATUS="APPROVE"`;
const fetchApprovedElections=()=>{
return DbConnection()
.query(APPROVED_ELECTION_SELECT_QUERY, {
//replacements: params,
type: DbConnection().QueryTypes.SELECT,
}).catch( (error) => {
console.log(error);
throw new DBError(error);
});
}



export default {
fetchElectionByIdWithTimelineData,
fetchAllElections,
fetchElectionsByStatus,
fetchApprovedElections,
}
48 changes: 48 additions & 0 deletions src/repository/review.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { DBError } from 'Errors';
import { DbConnection } from './dataSource';


const PAYMENT_STATUS_UPDATE_QUERY = `UPDATE PAYMENT
SET
STATUS = :status
WHERE
ID = :paymentId`;

const updatePaymentStatus = (paymentId,status) => {
const params = { 'status': status, 'paymentId': paymentId};
return DbConnection()
.query(PAYMENT_STATUS_UPDATE_QUERY,
{
replacements: params,
type: DbConnection().QueryTypes.UPDATE,
}).then((results) => {
return params;
}).catch((error) => {
throw new DBError(error);
});
};
//updatePaymentNote

const PAYMENT_NOTE_UPDATE_QUERY = `UPDATE PAYMENT
SET
NOTE = :note
WHERE
ID = :paymentId`;

const updatePaymentNote = (paymentId, note) => {
const params = { 'note': note, 'paymentId': paymentId };
return DbConnection()
.query(PAYMENT_NOTE_UPDATE_QUERY,
{
replacements: params,
type: DbConnection().QueryTypes.UPDATE,
}).then((results) => {
return params;
}).catch((error) => {
throw new DBError(error);
});
};
export default {
updatePaymentStatus,
updatePaymentNote,
}
10 changes: 10 additions & 0 deletions src/routes/activeElectionRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,15 @@ export const initActiveElectionRouter = (app) => {
.catch(error => next(error));
},
},
{
method: GET,
path: '/activeElectionsData',
handler: (req, res, next) => {
return ActiveElectionService.getApprovedElectionData(req)
.then((result) => res.status(200).send(result))
.catch(error => next(error));
},
},

]);
};
3 changes: 3 additions & 0 deletions src/routes/constants/URLSchema.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Joi from 'joi';

export const URL_SCHEMA = Joi.object().keys({

userId: Joi.string().max(36).regex(/^[A-Za-z0-9-]+$/),
teamId: Joi.string().max(36).regex(/^[A-Za-z0-9-]+$/),
nominationId: Joi.string().max(36).regex(/^[A-Za-z0-9-]+$/),
Expand All @@ -14,4 +15,6 @@ export const URL_SCHEMA = Joi.object().keys({
electionNominationId: Joi.string().max(36).regex(/^[A-Za-z0-9-]+$/),
status: Joi.string().max(10).regex(/^[A-Za-z-]+$/),
category: Joi.string().max(20),
paymentId: Joi.string().max(36).regex(/^[A-Za-z0-9-]+$/),

});
28 changes: 14 additions & 14 deletions src/routes/paymentRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import { createRoutes } from '../middleware/Router';
const paymentRouter = createRoutes();

export const initPaymentRouter = (app) => {
paymentRouter(app, [
{
// curl -H "Content-Type: application/json" -X GET http://localhost:9001/ec-election/elections/43680f3e-97ac-4257-b27a-5f3b452da2e6/payments
method: GET,
path: '/elections/:electionId/payments',
schema: {},
handler: (req, res, next) => {
return PaymentService.getPaymentsByElectionId(req)
.then((result) => res.status(200).send(result))
.catch(error => next(error));
paymentRouter(app, [
{
// curl -H "Content-Type: application/json" -X GET http://localhost:9001/ec-election/elections/43680f3e-97ac-4257-b27a-5f3b452da2e6/payments
method: GET,
path: '/elections/:electionId/payments',
schema: {},
handler: (req, res, next) => {
return PaymentService.getPaymentsByElectionId(req)
.then((result) => res.status(200).send(result))
.catch(error => next(error));

},
}
]);
};
},
}
]);
};
35 changes: 35 additions & 0 deletions src/routes/reviewRouter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import _ from 'lodash';
import { GET, POST ,PUT} from 'HttpMethods';
import { reviewService } from 'Service';
import { createRoutes } from '../middleware/Router';

const paymentRouter = createRoutes();

export const initReviewRouter = (app) => {
paymentRouter(app, [
{
// curl -H "Content-Type: application/json" -X GET http://localhost:9001/ec-election/review/378a33e1-5ad0-42f1-9403-dc9dbba32f4c/payments
method: PUT,
path: '/review/:paymentId/payments',
// schema: {},
handler: (req, res, next) => {
return reviewService.putPaymentsBypaymentId(req)
.then((result) => res.status(200).send(result))
.catch(error => next(error));

},
},
{
// curl -H "Content-Type: application/json" -X GET http://localhost:9001/ec-election/payments/378a33e1-5ad0-42f1-9403-dc9dbba32f4c/note
method: PUT,// /payments/:payment_id/note
path: '/payments/:paymentId/note',
// schema: {},
handler: (req, res, next) => {
return reviewService.putPaymentNoteBypaymentId(req)
.then((result) => res.status(200).send(result))
.catch(error => next(error));

},
},
]);
};
48 changes: 25 additions & 23 deletions src/routes/routerAggregator.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
import { initUserRouter } from './userRouter';
import { initDefaultRouter } from './defaultRouter';
import { initTeamRouter } from './teamRouter';
import { initNominationRouter } from './nominationRouter';
import { initElectionRouter } from './electionRouter';
import { initDivisionRouter } from './divisionRouter';
import { initModuleRouter } from './moduleRouter';
import { initObjectionRouter } from './objectionRouter';
import { initActiveElectionRouter } from './activeElectionRouter';
import { initElectionNominationRouter } from './electionNominationRouter';
import { initPaymentRouter } from './paymentRouter';
import {initUserRouter} from './userRouter';
import {initDefaultRouter} from './defaultRouter';
import {initTeamRouter} from './teamRouter';
import {initNominationRouter} from './nominationRouter';
import {initElectionRouter} from './electionRouter';
import {initDivisionRouter} from './divisionRouter';
import {initModuleRouter} from './moduleRouter';
import {initObjectionRouter} from './objectionRouter';
import {initActiveElectionRouter} from './activeElectionRouter';
import {initElectionNominationRouter} from './electionNominationRouter';
import {initPaymentRouter} from './paymentRouter';
import { initReviewRouter } from './reviewRouter';


export const initRoutes = (app) => {
initUserRouter(app);
initDefaultRouter(app);
initTeamRouter(app);
initObjectionRouter(app);
initNominationRouter(app);
initElectionRouter(app);
initDivisionRouter(app);
initModuleRouter(app);
initObjectionRouter(app);
initActiveElectionRouter(app);
initElectionNominationRouter(app);
initPaymentRouter(app);
initUserRouter(app);
initDefaultRouter(app);
initTeamRouter(app);
initObjectionRouter(app);
initNominationRouter(app);
initElectionRouter(app);
initDivisionRouter(app);
initModuleRouter(app);
initObjectionRouter(app);
initActiveElectionRouter(app);
initElectionNominationRouter(app);
initPaymentRouter(app);
initReviewRouter(app);
};
16 changes: 13 additions & 3 deletions src/service/activeElectionService.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { ServerError , ApiError } from 'Errors';
import ActiveElectionRepo from '../repository/activeElection';
import {ActiveElectionManager} from 'Managers';
import {ActiveElectionManager,ApprovedElectionManager} from 'Managers';
import _ from 'lodash';
import { executeTransaction } from '../repository/TransactionExecutor';
import ElectionRepo from "../repository/election";
import {HTTP_CODE_404} from "../routes/constants/HttpCodes";
const uuidv4 = require('uuid/v4');


Expand Down Expand Up @@ -87,9 +89,17 @@ const getActiveElectionByActiveElectionId = async (req) => {
throw new ApiError("ActiveElection not found");
}
};

const getApprovedElectionData =async () =>{
const elections = await ElectionRepo.fetchApprovedElections();
if(!_.isEmpty(elections)){
return ApprovedElectionManager.mapToApprovedElectionsDataModel(elections);
} else {
throw new ApiError("No Election found");
}
}
export default {
getActiveElectionByActiveElectionId,
updateActiveElectionByActiveElectionId,
saveActiveElectionData
saveActiveElectionData,
getApprovedElectionData
}
Loading