Skip to content

Commit

Permalink
Merge pull request #272 from YujithIsura/master
Browse files Browse the repository at this point in the history
This fixes #252
  • Loading branch information
YujithIsura authored Mar 3, 2020
2 parents cab8169 + 82b116a commit c047168
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 31 deletions.
2 changes: 2 additions & 0 deletions client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ axios.interceptors.request.use(function (config) {

sessionStorage.setItem("party_id", getCookie('party_id'));
sessionStorage.setItem("division_id", getCookie('division_id'));
sessionStorage.setItem("user", getCookie('user'));




Expand Down
5 changes: 2 additions & 3 deletions client/src/components/AdminMenu/AdminMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,9 @@ class ResponsiveDrawer extends React.Component {
var cookieValue = document.cookie.replace(/(?:(?:^|.*;\s*)scope\s*\=\s*([^;]*).*$)|^.*$/, "$1");
var scopes = decodeURIComponent(cookieValue).split(/ +/g)

var user_role = sessionStorage.getItem('role');
var user = sessionStorage.getItem('user');
Array.prototype.move = function(x, y){
this.splice(y, 0, this.splice(x, 1)[0]);
debugger;
return this;
};

Expand Down Expand Up @@ -184,7 +183,7 @@ class ResponsiveDrawer extends React.Component {

<Button color="inherit">
<PersonIcon style={{ marginRight: 5 }} />
{(user_role === 'cg_user') ? 'EC-Chairman' : (user_role === 'ac_user') ? ' Commissioner-General' : ''}
{user}
</Button>
<Button className={classes.logoutBtn} onClick={this.handleLogout} color="inherit">
<PowerSetting style={{ marginRight: 5 }} />
Expand Down
5 changes: 2 additions & 3 deletions client/src/components/MainMenu/MainMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ class ResponsiveDrawer extends React.Component {
scopes[indexNomination] = scopes[0];
scopes[0] = tempNomination;
}
console.log("ffffffffffffffffff",scopes);
var user_role = sessionStorage.getItem('role');
var user = sessionStorage.getItem('user');

const list = scopes.map((scope) => {
switch (scope) {
Expand Down Expand Up @@ -138,7 +137,7 @@ console.log("ffffffffffffffffff",scopes);

<Button color="inherit">
<PersonIcon style={{marginRight:5}}/>
{(user_role==='party_user') ? 'Party User' : (user_role==='ig_user') ? 'IG user' : ''}
{user}
</Button>
<Button onClick={this.handleLogout} color="inherit">
<PowerSetting style={{marginRight:5}}/>
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/MainMenuLogin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class ResponsiveDrawer extends React.Component {
scopes[indexNomination] = scopes[0];
scopes[0] = tempNomination;
}
var user_role = sessionStorage.getItem('role');
var user = sessionStorage.getItem('user');



Expand All @@ -98,7 +98,7 @@ class ResponsiveDrawer extends React.Component {

<Button color="inherit">
<PersonIcon style={{marginRight:5}}/>
{(user_role==='party_user') ? 'Party User' : (user_role==='ig_user') ? 'IG user' : ''}
{user}
</Button>
<Button onClick={this.handleLogout} color="inherit">
<PowerSetting style={{marginRight:5}}/>
Expand Down
20 changes: 12 additions & 8 deletions client/src/modules/election-model/state/ElectionAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ export const setPostModuleData = (val) => {

export function postCallElectionData(electionData) {
//TODO: config ids should get from the front end and the array should be dynamic
let newDate = new Date();

let allElectionModuleData = {
"moduleId": "1268362183761283718236",
"divisionCommonName":'Provintial',
"createdBy":'admin',
"createdAt":'',
"updatedAt":'',
"createdBy":sessionStorage.getItem('user'),
"createdAt":Date.parse(newDate),
"updatedAt":Date.parse(newDate),
"candidateFormConfiguration": [
{
candidateConfigId: '1',
Expand Down Expand Up @@ -143,7 +144,7 @@ export const submitElection = function saveElection(election) {
"name": election.name,
"id": "1268362183761283718236",
"divisionCommonName":'Provintial',
"createdBy":'admin',
"createdBy":sessionStorage.getItem('user'),
"createdAt":'',
"updatedAt":'',
"candidateFormConfiguration": [
Expand Down Expand Up @@ -225,6 +226,8 @@ export const setUpdatedTemplateData = (val) => {
}

export function editElection(moduleId,election) {
election.createdBy = sessionStorage.getItem('user');

return function (dispatch) {
const response = axios
.put(
Expand All @@ -233,7 +236,7 @@ export const setUpdatedTemplateData = (val) => {
)
.then(response => {
var electionNew= {createdAt: response.data.createdAt,
createdBy: 'admin',
createdBy: response.data.createdBy,
id: response.data.id,
lastModified: response.data.updatedAt,
moduleId: "",
Expand Down Expand Up @@ -405,6 +408,7 @@ export const setGetTemplateData = (val) => {
}

export function getElectionTemplateData(moduleId) {
let newDate = new Date();
if(moduleId===undefined){
return function (dispatch) {
const new_election_module= {
Expand All @@ -429,9 +433,9 @@ export function getElectionTemplateData(moduleId) {
let allElectionModuleData = {
"moduleId": moduleId,
"divisionCommonName":'Provintial',
"createdBy":'admin',
"createdAt":'',
"updatedAt":'',
"createdBy":sessionStorage.getItem('user'),
"createdAt":Date.parse(newDate),
"updatedAt":Date.parse(newDate),
"candidateFormConfiguration": [
{
candidateConfigId: '1',
Expand Down
3 changes: 1 addition & 2 deletions client/src/modules/election-model/state/ElectionReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,9 @@ export default function reducer(state = initialState, action) {
case GET_REJECTED_ELECTION_MODULE:
const AllElectionsPrev = state.AllElectionTemplates;
const i = findApprovalIndex(AllElectionsPrev, action.payload.id);
debugger;
return {
...state,
AllElectionTemplates: update(state.AllElectionTemplates, {[i]: {status: {$set: action.payload.status}}})
AllElectionTemplates: update(state.AllElectionTemplates, {[i]: {status: {$set: action.payload.status},createdBy: {$set: action.payload.createdBy}}})
};
// return {
// ...state,
Expand Down
10 changes: 5 additions & 5 deletions client/src/modules/election/state/ElectionAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ export function postCallElectionData(CallElectionData, electionData) {
"name":CallElectionData.name,
"module_id":CallElectionData.module_id,
"status":'PENDING',
"created_by":"admin",
"created_by":sessionStorage.getItem('user'),
"created_at":Date.parse(newDate),
"updated_at":Date.parse(newDate),
"timeLineData":
Expand Down Expand Up @@ -309,7 +309,7 @@ export function postCallElectionData(CallElectionData, electionData) {
"id":response.data,
"name":CallElectionData.name,
"status":'PENDING',
"createdBy":"admin",
"createdBy":sessionStorage.getItem('user'),
"lastModified":Date.parse(newDate),
"moduleId":CallElectionData.module_id
}
Expand Down Expand Up @@ -339,7 +339,7 @@ export function editCallElectionData(CallElectionData, electionId) {
"name":CallElectionData.name,
"module_id":CallElectionData.module_id,
"status":'PENDING',
"created_by":"admin",
"created_by":sessionStorage.getItem('user'),
"created_at":Date.parse(newDate),
"updated_at":Date.parse(newDate),
"timeLineData":
Expand All @@ -364,7 +364,7 @@ export function editCallElectionData(CallElectionData, electionId) {
{ ...allElectionData }
)
.then(response => {
const data={electionId:electionId,status:'PENDING'}
const data={createdBy:response.data.created_by,electionId:electionId,status:'PENDING'}
dispatch(setEditCallElectionData(data));
dispatch(openSnackbar({ message: CallElectionData.name + ' has been updated ' }));
}).catch(err => {
Expand Down Expand Up @@ -634,7 +634,7 @@ export function getCallElectionData(electionId,electionName,moduleId) {
"name":'asd',
"module_id":'xd',
"status":'PENDING',
"created_by":"admin",
"created_by":sessionStorage.getItem('user'),
"created_at":Date.parse(newDate),
"updated_at":Date.parse(newDate),
"timeLineData":
Expand Down
4 changes: 1 addition & 3 deletions client/src/modules/election/state/ElectionReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export default function reducer(state = initialState, action) {
const i = findApprovalIndex(AllElectionsPrev, action.payload.electionId);
return {
...state,
AllElections: update(state.AllElections, {[i]: {status: {$set: action.payload.status}}})
AllElections: update(state.AllElections, {[i]: {status: {$set: action.payload.status},createdBy: {$set: action.payload.createdBy},}})
};
case ELECTION_REVIEW_DATA://save timeline, electionConfig, allow nominaton
return {
Expand Down Expand Up @@ -171,9 +171,7 @@ export default function reducer(state = initialState, action) {
CallElectionData: action.payload
};
case DELETE_CALL_ELECTION_DATA:
console.log(action.payload);
const toDelete = state.AllElections.findIndex(x => x.id === action.payload);
debugger;
return {
...state,
AllElections: update(state.AllElections, { $splice: [[toDelete, 1]] } )
Expand Down
2 changes: 1 addition & 1 deletion client/src/modules/nomination/state/NominationAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export const onChangeApprovalData = (nominationApprovals) => {
export function onChangeApproval(nominations,id,status,reviewNote) {
return function (dispatch) {
let nominationApprovals = {
createdBy: 'admin',//TODO: yujith, change this to session user after creating the session
createdBy: sessionStorage.getItem('user'),
createdAt: Date.parse(new Date()),
updatedAt: Date.parse(new Date()),
status: status,
Expand Down
3 changes: 2 additions & 1 deletion server/src/repository/activeElection.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const ACTIVE_ELECTION_UPDATE_QUERY = `UPDATE ELECTION
SET
NAME = :name,
MODULE_ID = :module_id,
UPDATED_AT = :updated_at
UPDATED_AT = :updated_at,
CREATED_BY = :created_by
WHERE
ID = :id`;
const ACTIVE_ELECTION_STATUS_UPDATE_QUERY = `UPDATE ELECTION_APPROVAL
Expand Down
3 changes: 2 additions & 1 deletion server/src/repository/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ const ELECTION_MODULE_UPDATE_QUERY = `UPDATE ELECTION_MODULE
SET
NAME = :name,
DIVISION_COMMON_NAME = :divisionCommonName,
UPDATED_AT = :updatedAt
UPDATED_AT = :updatedAt,
CREATED_BY = :createdBy
WHERE
ID = :id`;

Expand Down
2 changes: 1 addition & 1 deletion server/src/service/activeElectionService.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const saveActiveElectionData = async (req) => {
const saveAllowedNominatonListData = await saveAllowedNominatonList(req,electionId);
await ActiveElectionRepo.saveAllowedNominations(electionId,saveAllowedNominatonListData, transaction);
await ActiveElectionRepo.savePendingElectionStatus(pendingStatusData, transaction);
return electionId;
return pendingStatusData;
});
}catch (e){
console.log(e);
Expand Down
3 changes: 2 additions & 1 deletion server/src/service/moduleService.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ const saveElectionModule = async (req) => {
if(moduleId !== undefined){
const name = req.body.name;
const divisionCommonName = req.body.divisionCommonName;
const createdBy = req.body.createdBy;
const updatedAt = Date.parse(new Date());
param = {'id':moduleId, "name":name, "divisionCommonName":divisionCommonName, "updatedAt":updatedAt }
param = {'id':moduleId, "name":name, "divisionCommonName":divisionCommonName, "updatedAt":updatedAt, "createdBy":createdBy }
await ModuleRepo.updateElectionModule(param,transaction);
const approvalParams = {'updatedAt':updatedAt, 'status':'PENDING','moduleId':moduleId,'reviewNote':''};
await ModuleRepo.updateTemplateStatus( approvalParams );
Expand Down

0 comments on commit c047168

Please sign in to comment.