Skip to content

Commit

Permalink
Merge pull request #314 from YujithIsura/master
Browse files Browse the repository at this point in the history
This fixes #306
  • Loading branch information
YujithIsura authored Mar 27, 2020
2 parents 65b5e7f + a50eb7e commit 179dfd8
Show file tree
Hide file tree
Showing 23 changed files with 287 additions and 56 deletions.
13 changes: 10 additions & 3 deletions client/src/components/AddParty/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,16 @@ class PartyRegistration extends React.Component {
if (name === 'secretaryName') {
this.setState({ errorTextSecretaryName: '' });
}
this.setState({
[name]: event.target.value,
});
if(name === 'address'){
this.setState({
[name]: event.target.value.replace(/[^a-zA-Z0-9,/ ]/g, ''),
});
}else{
this.setState({
[name]: event.target.value.replace(/[^a-zA-Z0-9 ]/g, ''),
});
}

};

handleSubmit = (e) => {
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/CreateElection/CreateElection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class FilledTextFields extends React.Component {
this.setState({errorTextTemplate:''});
}
this.setState({
[name]: event.target.value,
[name]: event.target.value.replace(/[^a-zA-Z0-9 ]/g, ''),
});
};

Expand Down
6 changes: 5 additions & 1 deletion client/src/components/DynamicForm/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ class DynamicForm extends React.Component {
}

onChange(event) {
this.setState(this.editValue(this.state, event.target.name, event.target.value));
if(event.target.name === 'ADDRESS'){
this.setState(this.editValue(this.state, event.target.name, event.target.value.replace(/[^a-zA-Z0-9,/ ]/g, '')));
}else{
this.setState(this.editValue(this.state, event.target.name, event.target.value.replace(/[^a-zA-Z0-9 ]/g, '')));
}
}

editValue(state, name, value){
Expand Down
13 changes: 10 additions & 3 deletions client/src/components/NominationPaymentUpdate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,16 @@ class NominationPayments extends React.Component {
if(name==='note'){
this.setState({errorTextNote:''});
}
this.setState({
[name]:event.target.value,
});
if(name==='depositor'){
this.setState({
[name]:event.target.value.replace(/[^a-zA-Z0-9 ]/g, ''),
});
}else{
this.setState({
[name]:event.target.value,
});
}

};

handleChangeAutocomplete = (name) => event => {
Expand Down
12 changes: 9 additions & 3 deletions client/src/components/NominationStep2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,15 @@ class NominationPayments extends React.Component {
if (name === 'depositeDate') {
this.setState({ errorTextDepositedDate: '' });
}
this.setState({
[name]: event.target.value,
});
if(name==='depositor'){
this.setState({
[name]:event.target.value.replace(/[^a-zA-Z0-9 ]/g, ''),
});
}else{
this.setState({
[name]:event.target.value,
});
}
};

handleChangeAutocomplete = (name) => event => {
Expand Down
13 changes: 10 additions & 3 deletions client/src/components/UpdateParty/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,16 @@ class PartyRegistration extends React.Component {
if (name === 'secretaryName') {
this.setState({ errorTextSecretaryName: '' });
}
this.setState({
[name]: event.target.value,
});

if(name === 'address'){
this.setState({
[name]: event.target.value.replace(/[^a-zA-Z0-9,/ ]/g, ''),
});
}else{
this.setState({
[name]: event.target.value.replace(/[^a-zA-Z0-9 ]/g, ''),
});
}
};

handleSubmit = (e) => {
Expand Down
4 changes: 2 additions & 2 deletions client/src/modules/election-model/DivisionConfig.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class DivisionConfig extends React.Component {
render() {
const classes = styles();
const handleChange = name => event => {
this.setState({ ...this.state, [name]: event.target.value });
this.setState({ ...this.state, [name]: event.target.value.replace(/[^a-zA-Z0-9 ]/g, '') });
if(name==='divisionCode'){
this.setState({ errorTextDivisionCode: '' });
}
Expand All @@ -110,7 +110,7 @@ class DivisionConfig extends React.Component {
if(name==='noOfCandidates'){
this.setState({ errorTextNoOfCandidates: '' });
}
this.props.electionChanged({ ...this.props.electionModule, [name]: event.target.value });
this.props.electionChanged({ ...this.props.electionModule, [name]: event.target.value.replace(/[^a-zA-Z0-9 ]/g, '') });
};

return (
Expand Down
2 changes: 1 addition & 1 deletion client/src/modules/election-model/ElectionConfig.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class ElectionConfig extends React.Component {
if(event && event.target ){
const newElectionModule = {...this.props.electionModule};
const target = event.target;
const value = target.type === 'checkbox' ? target.checked : target.value;
const value = target.type === 'checkbox' ? target.checked : target.value.replace(/[^a-zA-Z0-9_ ]/g, '');
const name = target.name;
const electionConf = {
electionModuleConfigId: name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class Dashboard extends React.Component {

handleChange = name => event => {
this.setState({
[name]: event.target.value,
[name]: event.target.value.replace(/[^a-zA-Z0-9 ]/g, ''),
errorTextModule: ''
});
};
Expand Down
3 changes: 2 additions & 1 deletion client/src/modules/election-model/state/ElectionAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ export const submitElection = function saveElection(election) {
dispatch(openSnackbar({ message: election.name + ' has been submitted for approval' }));
}
}).catch(err => {
dispatch(openSnackbar({ message: err.response.data.message }));
console.log(err)
});
}
Expand Down Expand Up @@ -249,7 +250,7 @@ export const setUpdatedTemplateData = (val) => {

dispatch(openSnackbar({ message: election.name + ' has been updated ' }));
}).catch(err => {
dispatch(openSnackbar({ message: ' Something went wrong!' }));
dispatch(openSnackbar({ message: err.response.data.message }));
console.log(err)
});
};
Expand Down
13 changes: 10 additions & 3 deletions client/src/modules/election/CallElection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,16 @@ class CallElection extends React.Component {
if (name === 'electionModule') {
this.setState({ errorTextModule: '' });
}
this.setState({
[name]: event.target.value,
});
if(name==='electionName'){
this.setState({
[name]: event.target.value.replace(/[^a-zA-Z0-9 ]/g, ''),
});
}else{
this.setState({
[name]: event.target.value,
});
}

};

asyncValidation = name => event => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ class Dashboard extends React.Component {

handleChange = name => event => {
this.setState({
[name]: event.target.value,
[name]: event.target.value.replace(/[^a-zA-Z0-9 ]/g, ''),
errorTextModule: ''
});
};
Expand Down
4 changes: 2 additions & 2 deletions client/src/modules/election/state/ElectionAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ export function postCallElectionData(CallElectionData, electionData) {
dispatch(receivePendingElection(allElectionDataNew));
dispatch(openSnackbar({ message: CallElectionData.name + ' has been submitted for approval' }));
}).catch(err => {
dispatch(openSnackbar({ message: ' Something went wrong' }));
dispatch(openSnackbar({ message: err.response.data.message }));
console.log(err)
});
};
Expand Down Expand Up @@ -374,7 +374,7 @@ export function editCallElectionData(CallElectionData, electionId) {
dispatch(setEditCallElectionData(data));
dispatch(openSnackbar({ message: CallElectionData.name + ' has been updated ' }));
}).catch(err => {
dispatch(openSnackbar({ message: ' Something went wrong' }));
dispatch(openSnackbar({ message: err.response.data.message }));
console.log(err)
});
};
Expand Down
2 changes: 1 addition & 1 deletion client/src/modules/nomination/Nomination_review.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ class NominationReview extends React.Component {

handleChange = name => event => {
this.setState({
[name]: event.target.value,
[name]: event.target.value.replace(/[^a-zA-Z0-9 ]/g, ''),
});
};

Expand Down
1 change: 1 addition & 0 deletions client/src/modules/nomination/state/NominationAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ export function postNominationPayments(candidatePayments,serialNo,division,party
dispatch(setData(newPayment));
dispatch(openSnackbar({ message:`Payment has been submitted for ${candidatePayments.division} by ${candidatePayments.partyName}`}));
}).catch(err => {
dispatch(openSnackbar({ message: err.response.data.message }));
console.log(err)
});
};
Expand Down
12 changes: 10 additions & 2 deletions server/src/routes/activeElectionRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import { GET, POST, PUT, DELETE } from 'HttpMethods';
import {ActiveElectionService} from 'Service';
import {createRoutes} from '../middleware/Router';
import ActiveElectionManager from '../manager/activeElection/activeElectionManager';
import {ACTIVE_ELECTION_EDIT_SCHEMA, GET_ACTIVE_ELECTION_BY_ID_SCHEMA} from './schema/activeElectionSchema';
import {ACTIVE_ELECTION_EDIT_SCHEMA,
GET_ACTIVE_ELECTION_BY_ID_SCHEMA,
ACTIVE_ELECTION_DATA_EDIT_SCHEMA,
ACTIVE_ELECTION_DATA_EDIT_SCHEMA_FOR_PUT,
ACTIVE_ELECTION_APPROVAL_SCHEMA
} from './schema/activeElectionSchema';
import { HTTP_CODE_404, HTTP_CODE_201, HTTP_CODE_200 } from '../routes/constants/HttpCodes';


Expand Down Expand Up @@ -70,6 +75,7 @@ export const initActiveElectionRouter = (app) => {
{
method: POST,
path: '/activeElectionsData',
schema: ACTIVE_ELECTION_DATA_EDIT_SCHEMA,
handler: (req, res, next) => {
return ActiveElectionService.saveActiveElectionData(req)
.then((result) => res.status(200).send(result))
Expand All @@ -79,6 +85,7 @@ export const initActiveElectionRouter = (app) => {
{
method: PUT,
path: '/activeElectionsData/:electionId',
schema: ACTIVE_ELECTION_DATA_EDIT_SCHEMA_FOR_PUT,
handler: (req, res, next) => {
return ActiveElectionService.saveActiveElectionData(req)
.then((result) => res.status(200).send(result))
Expand All @@ -96,7 +103,8 @@ export const initActiveElectionRouter = (app) => {
},
{
method: POST,
path: '/activeElections/:electionId/approve-active-election',
path: '/activeElections/:electionId/approve-active-election',
schema: ACTIVE_ELECTION_APPROVAL_SCHEMA,
handler: (req, res, next) => {
return ActiveElectionService.saveApproveElectionByElectionId(req)
.then((result) => res.status(HTTP_CODE_201).send(result))
Expand Down
10 changes: 9 additions & 1 deletion server/src/routes/moduleRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import { GET, POST, PUT, DELETE } from 'HttpMethods';
import { ModuleService, SupportDocService, CandidateService,ValidationService } from 'Service';
import { createRoutes } from '../middleware/Router';
import ModuleManager from '../manager/module/moduleManager';
import { MODULE_EDIT_SCHEMA, GET_MODULE_BY_ID_SCHEMA } from './schema/moduleSchema';
import { MODULE_EDIT_SCHEMA,
GET_MODULE_BY_ID_SCHEMA,
ELECTION_TEMPLATE_DATA_EDIT_SCHEMA_FOR_PUT,
ELECTION_TEMPLATE_DATA_EDIT_SCHEMA,
ELECTION_TEMPLATE_APPROVAL_SCHEMA
} from './schema/moduleSchema';

const moduleRouter = createRoutes();

Expand Down Expand Up @@ -100,6 +105,7 @@ export const initModuleRouter = (app) => {
{
method: POST,
path: '/election-modules',
schema: ELECTION_TEMPLATE_DATA_EDIT_SCHEMA,
handler: (req, res, next) => {
return ModuleService.saveElectionModule(req)
.then((result) => res.status(200).send(result))
Expand All @@ -109,6 +115,7 @@ export const initModuleRouter = (app) => {
{
method: PUT,
path: '/election-modules/:moduleId',
schema: ELECTION_TEMPLATE_DATA_EDIT_SCHEMA_FOR_PUT,
handler: (req, res, next) => {
return ModuleService.saveElectionModule(req)
.then((result) => res.status(200).send(result))
Expand Down Expand Up @@ -137,6 +144,7 @@ export const initModuleRouter = (app) => {
{
method: PUT,
path: '/election-modules/:moduleId/approve-election-templates',
schema: ELECTION_TEMPLATE_APPROVAL_SCHEMA,
handler: (req, res, next) => {
return ModuleService.ApproveElectionTemplateByModuleId(req)
.then((result) => res.status(200).send(result))
Expand Down
19 changes: 13 additions & 6 deletions server/src/routes/nominationRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import _ from 'lodash';
import { GET, POST, PUT, DELETE } from 'HttpMethods';
import { createRoutes } from '../middleware/Router';
import { PaymentService, CandidateService, SupportDocService, NominationService, UploadService} from 'Service';
import { SAVE_PAYMENT_SCHEMA, UPDATE_PAYMENT_SCHEMA, SAVE_SUPPORT_DOC_SCHEMA, UPDATE_SUPPORT_DOC_SCHEMA, SAVE_CANDIDATE_SCHEMA, SAVE_CANDIDATE_SUPPORT_DOCS_SCHEMA, SAVE_NOMINATION_APPROVE_SCHEMA } from './schema/nominationSchema';
import { SAVE_PAYMENT_SCHEMA,
UPDATE_PAYMENT_SCHEMA,
SAVE_SUPPORT_DOC_SCHEMA,
UPDATE_SUPPORT_DOC_SCHEMA,
SAVE_CANDIDATE_SCHEMA,
SAVE_CANDIDATE_SUPPORT_DOCS_SCHEMA,
SAVE_NOMINATION_APPROVE_SCHEMA,
} from './schema/nominationSchema';
import { HTTP_CODE_404, HTTP_CODE_201, HTTP_CODE_200 } from '../routes/constants/HttpCodes';
const multer = require('multer');
const zip = require('express-zip');
Expand Down Expand Up @@ -38,7 +45,7 @@ export const initNominationRouter = (app) => {
{
method: POST,
path: '/nominations/candidates',
// schema: SAVE_CANDIDATE_SCHEMA,
schema: SAVE_CANDIDATE_SCHEMA,
handler: (req, res, next) => {
return CandidateService.saveCandidateByNominationId(req)
.then((result) => res.status(HTTP_CODE_201).send(result))
Expand Down Expand Up @@ -87,9 +94,8 @@ export const initNominationRouter = (app) => {
{
method: POST,
path: '/nominations/:candidateId/candidates',
// schema: SAVE_CANDIDATE_SCHEMA,
schema: SAVE_CANDIDATE_SCHEMA,
handler: (req, res, next) => {
console.log("uuuuuuuuuuuuuuuuuuuuuuuuuuu",req);
return CandidateService.saveCandidateByNominationId(req)
.then((result) => res.status(HTTP_CODE_200).send(result))
.catch(error => next(error));
Expand All @@ -99,7 +105,7 @@ export const initNominationRouter = (app) => {
// curl -H "Content-Type: application/json" -X GET http://localhost:9001/ec-election/nominations/a0e4a9c9-4841-45df-9600-f7a607400ab6/payments
method: GET,
path: '/nominations/:nominationId/payments',
schema: {},
// schema: SAVE_PAYMENT_SCHEMA,
handler: (req, res, next) => {
return PaymentService.getPaymentByNominationId(req)
.then((result) => res.status(HTTP_CODE_200).send(result))
Expand All @@ -109,6 +115,7 @@ export const initNominationRouter = (app) => {
{
method: POST,
path: '/nominations/payments',
schema: SAVE_PAYMENT_SCHEMA,
handler: (req, res, next) => {
return PaymentService.createPaymentByNominationId(req)
.then((result) => res.status(HTTP_CODE_201).send(result))
Expand All @@ -118,7 +125,7 @@ export const initNominationRouter = (app) => {
{
method: PUT,
path: '/nominations/:paymentId/payments',
// schema: UPDATE_PAYMENT_SCHEMA,
schema: UPDATE_PAYMENT_SCHEMA,
handler: (req, res, next) => {
return PaymentService.updatePaymentByNominationId(req)
.then((result) => res.status(HTTP_CODE_201).send(result))
Expand Down
Loading

0 comments on commit 179dfd8

Please sign in to comment.