Skip to content

Commit

Permalink
Added button to delete all votes
Browse files Browse the repository at this point in the history
  • Loading branch information
guillecro committed Sep 21, 2023
1 parent d53af82 commit 3fd7af9
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 3 deletions.
67 changes: 65 additions & 2 deletions lib/admin/admin-stats/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export default class AdminStats extends Component {
facultades: {},
claustros: {},
errorVotacion: false,
errorGeneral: false
errorGeneral: false,
showFakeDeleteVotes: true,
showTrueDeleteVotes: false
}
}

Expand Down Expand Up @@ -100,13 +102,46 @@ export default class AdminStats extends Component {
})
}

preDeleteVotes = () => {
this.setState({
isLoadingVotacion: true,
isLoading: true
})
this.deleteVotes()
}


deleteVotes = () => {
window.fetch(`/api/padron/votes/clean`, {
method: 'DELETE',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
})
.then((res) => {
if (res.status === 200) {
return res
}
})
.then((res) => res.json())
.then((res) => {
this.getStats()
this.getStatsVotacion()
})
.catch((err) => {
console.log(err)
})
}

render () {

// const { forum } = this.props
let { users, userNotEmailValidated, topics, likes, attendies, comments,
replies, emailsNotValidated, votesCount, dniCount, isLoading,
usersWhoDidntVotedCount, isLoadingVotacion, votosOnline, facultades, claustros,
votosPresencial } = this.state
votosPresencial, showFakeDeleteVotes, showTrueDeleteVotes } = this.state

let facultadesRows = () => {
let rows = []
Expand Down Expand Up @@ -288,6 +323,34 @@ export default class AdminStats extends Component {
</a>
</div>
</div>
{/* DANGER ZONE: Limpiar votos */}
<div className="alert alert-danger" role="alert">
<div className="clearfix">
<div className="pull-left">
<p><b>Borrar todos los votos</b><br/>Para limpiar la base de datos de votos, haga clic y confirme la acción</p>
</div>
{
showFakeDeleteVotes && <div className="pull-right">
<button className='btn btn-danger' onClick={() => { this.setState({ showFakeDeleteVotes: false, showTrueDeleteVotes: true }) }}>
Limpiar votos
</button>
</div>
}
{
showTrueDeleteVotes && <div className="pull-right text-right">
<p><b>¿Está seguro?</b></p>
<div className="btn-group">
<button className='btn' onClick={() => { this.setState({ showFakeDeleteVotes: true, showTrueDeleteVotes: false }) }}>
Cancelar
</button>
<button className='btn btn-danger' onClick={this.preDeleteVotes}>
Confirmar
</button>
</div>
</div>
}
</div>
</div>
<p className='h3'><i className="icon-bar-chart"></i> Registros sin validar</p>
<div className="clearfix">
<div className="pull-left">
Expand Down
15 changes: 14 additions & 1 deletion lib/api/padron.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,17 @@ app.post('/padron/new',
log('OK! New entry in padron')
res.status(200).json(newPadron)
})
})
})

app.delete('/padron/votes/clean',
restrict,
staff,
function (req, res, next) {
log('Cleaning votes')
Vote.remove({}, function (err, removed) {
if (err) return next(err)
log('OK! Votes cleaned')
res.status(200).json(removed)
})
}
)

0 comments on commit 3fd7af9

Please sign in to comment.