Skip to content
Snippets Groups Projects
Commit 0847c34d authored by Thomas Bouquet's avatar Thomas Bouquet
Browse files

Add part

parent a5762a5d
No related branches found
No related tags found
No related merge requests found
......@@ -73,6 +73,20 @@ function getParticipants(req, res){
con.end();
}
function getParticipantsIdentifiants(req, res){
var con = mysql.createConnection(dbConfig);
var query = "SELECT id FROM Participant WHERE deleted = 0;"
con.connect();
con.query(query, (err, result) => {
if(err){
console.log(err)
return res.send({success: false})
}
return res.send(result)
});
con.end();
}
function getParticipantsById(req, res){
var con = mysql.createConnection(dbConfig);
var query = "SELECT id,name FROM Participant WHERE deleted = 0 AND id = "+req.query.id+" ORDER BY NAME ASC;"
......@@ -143,4 +157,4 @@ function deleteParticipant(req, res){
con.end();
}
module.exports = {getClassementIndividuel,getParticipants,addNewParticipant,updateParticipant,deleteParticipant,getNombreParticipants,addNewParticipantWithId,getParticipantsById}
module.exports = {getClassementIndividuel,getParticipants,addNewParticipant,updateParticipant,deleteParticipant,getNombreParticipants,addNewParticipantWithId,getParticipantsById,getParticipantsIdentifiants}
......@@ -18,5 +18,6 @@ router.get('/evenement', controller.evenement.getEvenements);
router.get('/distance_totale',controller.scores.getDistanceTotale);
router.get('/nombre_participants',controller.participant.getNombreParticipants);
router.get('/participants_by_id',controller.participant.getParticipantsById);
router.get('/participants_ids',controller.participant.getParticipantsIdentifiants);
module.exports = router;
import React, {useState,useEffect} from 'react';
import axios from 'axios';
import { useIsParticipant } from '../../../hooks/authTools';
const addParticipant = (props) => {
axios.post('/api/admin/new_participant',
......@@ -17,17 +18,9 @@ const addParticipant = (props) => {
export default function AddIfNotExists(props) {
var [participant,setParticipant] = useState([]);
useEffect(() => {
const interval = setInterval(() => {
axios.get('api/participants_by_id?id='+props.id).then((response) => setParticipant(response.data));
}, 500);
return () => clearInterval(interval);
}, []);
if ((participant[0] === undefined)) {
if (!useIsParticipant(props)) {
console.log("hey !");
addParticipant(props);
}
console.log(participant.data.args)
}
\ No newline at end of file
......@@ -37,7 +37,12 @@ function Submit (props) {
window.location='/Input';
}, (error) => {
console.log(error);
});
}).then(AddParticipantIfNotExists(
{
id: props.nom.value,
name: props.nom.label
}
));
};
......
......@@ -36,3 +36,18 @@ export function useIsStaff() {
return false||useIsAdmin()
}
}
export function useIsParticipant(props) {
const [part, setPart] = useState([]);
const [initialize, setInitialize] = useState(true);
if (initialize) {
axios.get('/api/participants_ids').then((response) => setPart(response.data));
setInitialize(false);
}
if (part.includes(props.id)) {
return true
} else {
return false
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment