Skip to content
Snippets Groups Projects
Commit b82fbea8 authored by ExtraDev's avatar ExtraDev
Browse files

add route to add entry with id_tag, add edit components...

parent 9626d3ef
No related branches found
No related tags found
No related merge requests found
......@@ -128,6 +128,30 @@ app.get('/entry', (req, res) => {
res.json(result);
});
});
app.get('/test', (req, res) => {
let date = new Date();
date.setHours(date.getHours() + 1);
console.log(date);
res.end();
});
app.post('/entry', (req, res) => {
let id_tag = req.body.id_tag;
let time_stamp = new Date();
time_stamp.setHours(time_stamp.getHours() + 1);
console.log(req.body);
if (!id_tag) {
res.status(http_status_codes_1.default.BAD_REQUEST).send({ error: "Missing argument" });
console.log("error no tag");
return;
}
const query = "INSERT INTO `entry`(`time_stamp`, `id_tag`) VALUES (?,?)";
exports.db.query(query, [time_stamp, id_tag], (err, result) => {
if (err) {
res.status(http_status_codes_1.default.INTERNAL_SERVER_ERROR).send({ error: "Something wrong append" });
}
res.status(http_status_codes_1.default.OK).send();
});
});
app.listen(port, () => {
console.log(`[server]: Server is running at https://localhost:${port}`);
});
......@@ -162,6 +162,37 @@ app.get('/entry', (req: Request, res: Response) => {
)
})
app.get('/test', (req: Request, res: Response) => {
let date = new Date();
date.setHours(date.getHours() + 1)
console.log(date)
res.end();
})
app.post('/entry', (req: Request, res: Response) => {
let id_tag = req.body.id_tag;
let time_stamp = new Date();
time_stamp.setHours(time_stamp.getHours() + 1)
console.log(req.body)
if(!id_tag) {
res.status(StatusCode.BAD_REQUEST).send({error:"Missing argument"})
console.log("error no tag")
return
}
const query = "INSERT INTO `entry`(`time_stamp`, `id_tag`) VALUES (?,?)";
db.query(query, [time_stamp, id_tag], (err, result) => {
if (err) {
res.status(StatusCode.INTERNAL_SERVER_ERROR).send({error: "Something wrong append"});
}
res.status(StatusCode.OK).send();
})
})
app.listen(port, () => {
console.log(`[server]: Server is running at https://localhost:${port}`);
})
\ No newline at end of file
......@@ -9,10 +9,10 @@
<Router>
<header>
<h1 id="title">Boldor</h1>
<Link to="/">Home</Link>
<Link to="teams">Équipes</Link>
<Link to="team">Gestion des équipes</Link>
<Link to="entry">Résultats</Link>
<Link class="link" to="/">Home</Link>
<Link class="link" to="teams">Équipes</Link>
<Link class="link" to="team">Gestion des équipes</Link>
<Link class="link" to="entry">Résultats</Link>
</header>
<main>
......@@ -56,6 +56,10 @@
text-align: center;
}
.link {
background-color: brown;
}
main {
width: 80%;
max-width: 1024px;
......
......@@ -28,6 +28,29 @@
}
getEntries(year_selected);
function sendEntry() {
let body_data = {
id_tag: "19040562"
};
fetch("http://localhost:8000/entry", {
method: "POST",
body: JSON.stringify(body_data),
headers: {
"Content-type": "application/json; charset=UTF-8",
},
}).then(function (response) {
if (!response.ok) return Promise.reject(response.status);
return response.json();
})
.then(function (data) {
console.log("okey" + data);
})
.catch(function (error) {
console.log("Error: " + error);
});
}
</script>
<div class="container">
......@@ -67,6 +90,8 @@
</tr>
{/each}
</table>
<button on:click={sendEntry}>Add entry</button>
</div>
<style>
......
......@@ -22,9 +22,9 @@
});
}
const edition_url = "http://localhost:8000/editions";
const EDITION_URL = "http://localhost:8000/editions";
let editions = [];
fetch(edition_url)
fetch(EDITION_URL)
.then((response) => response.json())
.then((editions_data) => {
editions = editions_data;
......@@ -49,7 +49,7 @@
year_selected: year_selected
};
fetch(TEAMS_URL, {
fetch("http://localhost:8000/teams", {
method: "POST",
body: JSON.stringify(body_data),
headers: {
......@@ -74,11 +74,22 @@
getAvailableTags(year_selected);
}
function selectTeam(index) {
for (let i in teams) {
if(teams[i].id_team == index) {
team_name = teams[i].name;
team_participants = teams[i].participants;
tag_selected = teams[i].id_tag;
}
}
}
getTeams()
getAvailableTags(year_selected);
</script>
<div class="container">
<h1>Création d'équipe</h1>
<div id="create">
<form action="#">
<div class="form-group">
......@@ -133,7 +144,9 @@
<td>{team.name}</td>
<td>{team.participants}</td>
<td>{team.id_tag}</td>
<td>...</td>
<td>
<button on:click={()=>selectTeam(team.id_team)} >Edit</button>
</td>
</tr>
{/each}
</table>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment