Skip to content

Commit

Permalink
Merge pull request #287 from YujithIsura/master
Browse files Browse the repository at this point in the history
backend validation added for party delete
  • Loading branch information
YujithIsura authored Mar 12, 2020
2 parents 71a5540 + 225f5d4 commit 155b8e0
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 16 deletions.
10 changes: 8 additions & 2 deletions client/src/components/AddParty/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ const styles = theme => ({
marginBottom: 20,
marginTop: 50
},
logocontainer: {
height: '100%',
marginTop:-55
},
});

class PartyRegistration extends React.Component {
Expand Down Expand Up @@ -540,8 +544,10 @@ class PartyRegistration extends React.Component {
<span ><FileUpload value={this.state.paySlip} doneElement={doneElement} onSelectFiles={this.onSelectFiles} /></span>
</span>
</Grid>
<Grid style={{marginTop:30,marginLeft:-10}}container item lg={4}>
<img src={this.state.file}/>
<Grid style={{marginTop:30,marginLeft:-10}} container item lg={4}>
<div className={classes.logocontainer} >
<img style={{maxWidth: 60,margin:25}} src={this.state.file}/>
</div>
</Grid>
</Grid>

Expand Down
80 changes: 80 additions & 0 deletions client/src/components/ElectionTemplateList/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import AppBar from '@material-ui/core/AppBar';
import Tabs from '@material-ui/core/Tabs';
import Tab from '@material-ui/core/Tab';
import Typography from '@material-ui/core/Typography';


function TabContainer(props) {
return (
<Typography component="div" style={{ padding: 8 * 3 }}>
{props.children}
</Typography>
);
}

TabContainer.propTypes = {
children: PropTypes.node.isRequired,
};

const styles = theme => ({
root: {
flexGrow: 1,
width: '100%',
backgroundColor: theme.palette.background.paper,
},
tabs: {
backgroundColor: '#dcdfe5',
}
});

class ScrollableTabsButtonAuto extends React.Component {
state = {
value: 0,
};

handleChange = (event, value) => {
this.setState({ value });
};

render() {
const { classes , customProps ,onCloseModal,callElectionPendingElements,callElectionRejectedElements,callElectionApproveElements } = this.props;
const { value } = this.state;

return (
<div className={classes.root}>
<AppBar style={{color:'black'}} position="static" >
<Tabs
classes={{flexContainer: classes.tabs}}
value={value}
onChange={this.handleChange}
// indicatorColor="primary"
// textColor="primary"
scrollable
scrollButtons="auto"
>
<Tab label="Pending Templates" />
<Tab label="Approved Templates" />
<Tab label="Rejected Templates" />


</Tabs>
</AppBar>
{value === 0 && <TabContainer>{callElectionPendingElements}</TabContainer>}
{value === 1 && <TabContainer>{callElectionApproveElements}</TabContainer>}
{value === 2 && <TabContainer>{callElectionRejectedElements}</TabContainer>}


</div>
);

}
}

ScrollableTabsButtonAuto.propTypes = {
classes: PropTypes.object.isRequired,
};

export default withStyles(styles)(ScrollableTabsButtonAuto);
4 changes: 0 additions & 4 deletions client/src/components/UpdateParty/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ class PartyRegistration extends React.Component {


handleChange = (name) => event => {
debugger;
if (name === 'phone') {
this.setState({ errorTextPhone: '' });
}
Expand Down Expand Up @@ -178,7 +177,6 @@ class PartyRegistration extends React.Component {
this.setState({ errorTextSecretaryName: 'emptyField' });
goNext = false;
}
debugger;

if (this.state.phoneList.length === 0 || this.state.phoneList.length === null) {
this.setState({ errorTextPhone: 'emptyField' });
Expand All @@ -189,7 +187,6 @@ class PartyRegistration extends React.Component {
this.setState({ errorTextFax: 'emptyField' });
goNext = false;
}
debugger;
if (goNext) {
updateParty(this.state.partyId,this.state);
onCloseModal();
Expand Down Expand Up @@ -305,7 +302,6 @@ debugger;
}else{
var faxList = [];
}
debugger;
getPartyLogo(PartyDetails.fileName);
this.setState({partyName:PartyDetails.partyName});
this.setState({partyType:PartyDetails.partyType});
Expand Down
4 changes: 2 additions & 2 deletions client/src/modules/election-model/Template_review.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import AdminMenu from '../../components/AdminMenu/AdminMenu';
import CallElectionList from '../../components/CallElectionList';
import ElectionTemplateList from '../../components/ElectionTemplateList';
import CallElection from '../../modules/election/CallElection';
import Typography from '@material-ui/core/Typography';
import Grid from '@material-ui/core/Grid';
Expand Down Expand Up @@ -266,7 +266,7 @@ class Home extends React.Component {

<Grid item xs={8} >
<div style={{ width: '100%' }}>
<CallElectionList callElectionApproveElements={callElectionApproveElements} callElectionPendingElements={callElectionPendingElements} callElectionRejectedElements={callElectionRejectedElements}></CallElectionList>
<ElectionTemplateList callElectionApproveElements={callElectionApproveElements} callElectionPendingElements={callElectionPendingElements} callElectionRejectedElements={callElectionRejectedElements}></ElectionTemplateList>
</div>
</Grid>
<Grid item xs={5} >
Expand Down
4 changes: 3 additions & 1 deletion client/src/modules/party/state/PartyAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export function saveParty(partyDetails) {
dispatch(setData(newPartyData));
dispatch(openSnackbar({ message:`New party has been registered successfully!`}));
}).catch(err => {
dispatch(openSnackbar({ message: err.response.data.message }));
console.log(err)
});
};
Expand Down Expand Up @@ -125,6 +126,7 @@ export function updateParty(teamId,partyDetails) {
dispatch(setUpdateData(newPartyData));
dispatch(openSnackbar({ message:`The party has been updated successfully!`}));
}).catch(err => {
dispatch(openSnackbar({ message: err.response.data.message }));
console.log(err)
});
};
Expand Down Expand Up @@ -173,7 +175,7 @@ export function deleteParty(teamId) {
dispatch(
setDeleteParty(getDeletedParty)
);
dispatch(openSnackbar({ message: "Candidate was deleted successfully!"}));
dispatch(openSnackbar({ message: "Party was deleted successfully!"}));
}).catch(err => {
const getDeletedParty = [];
dispatch(
Expand Down
16 changes: 15 additions & 1 deletion server/src/repository/team.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,19 @@ const updateTeamStatus = (partyId) => {
});
};

const TEAM_SELECT_QUERY_FROM_NOMINATION = `SELECT * FROM NOMINATION WHERE TEAM_ID=:team_id`;

const teamValidation = (team_id) => {
const params = { team_id: team_id };
return DbConnection()
.query(TEAM_SELECT_QUERY_FROM_NOMINATION,
{
replacements: params,
type: DbConnection().QueryTypes.SELECT,
}).catch((error) => {
throw new DBError(error);
});
};



Expand All @@ -153,5 +166,6 @@ export default {
fetchAllTeamsByTeamType,
insertTeam,
updateTeam,
updateTeamStatus
updateTeamStatus,
teamValidation
}
18 changes: 12 additions & 6 deletions server/src/service/teamService.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ServerError , ApiError } from 'Errors';
import TeamRepo from '../repository/team';
import {TeamManager} from 'Managers';
import _ from 'lodash';
import {HTTP_CODE_404} from '../routes/constants/HttpCodes';
import {HTTP_CODE_404,HTTP_CODE_403} from '../routes/constants/HttpCodes';
const uuidv4 = require('uuid/v4');


Expand Down Expand Up @@ -99,7 +99,7 @@ const createTeam = async (req) => {
await TeamRepo.insertTeam(teamData);
return teamData;
} catch (e) {
throw new ServerError("server error");
throw e;
}
};

Expand Down Expand Up @@ -148,18 +148,24 @@ const updateTeamById = async (req) => {
await TeamRepo.updateTeam(teamData);
return teamData;
} catch (e) {
throw new ServerError("server error");
throw e;
}
};

//Delete party details for a particular party
const deletePartyById = async (req) => {
try {
const partyId = req.params.teamId;
await TeamRepo.updateTeamStatus(partyId);
return partyId;
const partyExist = await TeamRepo.teamValidation(partyId);
if(_.isEmpty(partyExist)){
await TeamRepo.updateTeamStatus(partyId);
return partyId;
}else{
throw new ApiError("Sorry, This party already been used!",HTTP_CODE_403);
}

} catch (e) {
throw new ServerError("server error");
throw e;
}
};

Expand Down

0 comments on commit 155b8e0

Please sign in to comment.