Compare commits

..

No commits in common. "53275f6c1171da3f867cdd32ab76a3eab940c3f0" and "2961cbb1fa9504123d5536ea97f89e7c502d71db" have entirely different histories.

11 changed files with 276 additions and 273 deletions

View File

@ -479,10 +479,10 @@ if __name__ == '__main__':
nbMotifs : int = 10 nbMotifs : int = 10
store_table(nbMotifs, "motifs", tablesDict["motifs"]) store_table(nbMotifs, "motifs", tablesDict["motifs"])
nbPieces : int = 50 nbPieces : int = 100
store_table(nbPieces, "pieces", tablesDict["pieces"]) store_table(nbPieces, "pieces", tablesDict["pieces"])
nbPiecesComp : int = 5 nbPiecesComp : int = 10
store_table(nbPiecesComp, "pieces_complexes", store_table(nbPiecesComp, "pieces_complexes",
tablesDict["pieces_complexes"]) tablesDict["pieces_complexes"])
@ -492,7 +492,7 @@ if __name__ == '__main__':
# #
########################################################################### ###########################################################################
nbModeles : int = 10 nbModeles : int = 5
funcGen = lambda : tablesDict["modeles"]( funcGen = lambda : tablesDict["modeles"](
give_used_key(idMembreDict), give_used_key(idMembreDict),
give_used_key(idModeleDict) give_used_key(idModeleDict)
@ -638,7 +638,25 @@ if __name__ == '__main__':
) )
generate_table(nbVarier, "varier", funcGen) generate_table(nbVarier, "varier", funcGen)
### The following code is in `convert_data.py`. ###########################################################################
#
# To write `insert.sql`.
#
###########################################################################
# Remove duplicatas.
for nameTable in tablesDict:
remove_duplicata(give_path_file(nameTable))
# Writing in `insert.sql`.
fileSql = open("src/insert.sql", 'w+')
fileSql.write("TRUNCATE " + ', '.join(tablesDict) + ";\n")
fileSql.write("\n")
fileSql.close()
with open("src/insert.sql", 'a') as fileSql:
for nameTable in tablesDict:
convert_table_to_sql(give_path_file(nameTable), nameTable)
############################################################################### ###############################################################################

View File

@ -510,26 +510,25 @@ INSERT INTO contenir VALUES
(134, 900, 40), (134, 900, 40),
(134, 130, 78), (134, 130, 78),
(134, 133, 37), (134, 133, 37),
(235, 13, 27),
(235, 183, 18),
(235, 20, 26),
(235, 253, 26),
(235, 606, 13),
(235, 777, 10),
(235, 985, 12),
(235, 219, 24), (235, 219, 24),
(235, 444, 34), (235, 444, 34),
(235, 498, 14), (235, 498, 14),
(240, 183, 18), (235, 627, 43),
(240, 20, 26), (235, 797, 27),
(240, 253, 26), (235, 803, 42),
(240, 606, 13), (235, 886, 34),
(240, 777, 10), (235, 133, 59),
(240, 985, 12), (235, 210, 34),
(235, 288, 72),
(235, 945, 92),
(240, 13, 79), (240, 13, 79),
(240, 183, 13),
(240, 210, 83), (240, 210, 83),
(240, 233, 70), (240, 233, 70),
(240, 334, 92), (240, 334, 92),
(240, 423, 58),
(240, 466, 37),
(240, 571, 35),
(284, 210, 12), (284, 210, 12),
(284, 335, 47), (284, 335, 47),
(284, 498, 40), (284, 498, 40),
@ -599,30 +598,36 @@ INSERT INTO contenir VALUES
(520, 335, 47), (520, 335, 47),
(520, 498, 40), (520, 498, 40),
(520, 650, 30), (520, 650, 30),
(530, 233, 33),
(530, 288, 46),
(530, 304, 10),
(530, 355, 50),
(530, 488, 37),
(530, 797, 19),
(530, 130, 39), (530, 130, 39),
(530, 184, 37), (530, 184, 37),
(530, 232, 31), (530, 232, 31),
(530, 304, 61),
(530, 334, 72), (530, 334, 72),
(530, 355, 38),
(530, 36, 12),
(530, 498, 98),
(530, 580, 14),
(530, 650, 48),
(530, 776, 23),
(530, 797, 31),
(530, 921, 10), (530, 921, 10),
(530, 935, 79), (530, 935, 79),
(538, 130, 19),
(538, 133, 15),
(538, 210, 47),
(538, 375, 15),
(538, 501, 23),
(538, 734, 13),
(538, 921, 41),
(538, 935, 34),
(538, 13, 40), (538, 13, 40),
(538, 210, 18),
(538, 219, 83), (538, 219, 83),
(538, 304, 66), (538, 304, 66),
(538, 334, 77), (538, 334, 77),
(538, 335, 24),
(538, 36, 43),
(538, 466, 53),
(538, 501, 18),
(538, 650, 93),
(538, 686, 95),
(538, 726, 48),
(538, 859, 64),
(538, 935, 85),
(538, 945, 90),
(538, 963, 55),
(566, 13, 17), (566, 13, 17),
(566, 130, 67), (566, 130, 67),
(566, 183, 40), (566, 183, 40),
@ -640,41 +645,58 @@ INSERT INTO contenir VALUES
(566, 734, 13), (566, 734, 13),
(566, 776, 56), (566, 776, 56),
(566, 945, 87), (566, 945, 87),
(579, 130, 19), (579, 133, 22),
(579, 133, 15),
(579, 210, 47),
(579, 375, 15),
(579, 501, 23),
(579, 734, 13),
(579, 921, 41),
(579, 935, 34),
(579, 184, 82), (579, 184, 82),
(579, 20, 25), (579, 20, 25),
(579, 355, 68), (579, 355, 68),
(579, 375, 76),
(579, 423, 82),
(579, 501, 82),
(579, 571, 98),
(579, 627, 24),
(579, 650, 82),
(579, 859, 74),
(579, 886, 77),
(579, 900, 62),
(579, 945, 58),
(579, 963, 87),
(579, 985, 93), (579, 985, 93),
(624, 130, 19), (624, 13, 30),
(624, 133, 15), (624, 130, 36),
(624, 210, 47), (624, 184, 75),
(624, 375, 15), (624, 210, 94),
(624, 501, 23), (624, 334, 83),
(624, 734, 13), (624, 335, 95),
(624, 921, 41), (624, 375, 53),
(624, 935, 34), (624, 423, 26),
(624, 233, 33), (624, 501, 25),
(624, 288, 46), (624, 529, 21),
(624, 304, 10), (624, 580, 49),
(624, 355, 50), (624, 606, 42),
(624, 488, 37), (624, 734, 29),
(624, 797, 19), (624, 797, 75),
(63, 210, 47), (624, 803, 30),
(63, 375, 15), (624, 886, 83),
(63, 501, 23), (624, 900, 25),
(63, 734, 13), (624, 985, 13),
(63, 921, 41),
(63, 935, 34),
(63, 13, 28), (63, 13, 28),
(63, 130, 95), (63, 130, 95),
(63, 133, 22), (63, 133, 22),
(63, 183, 56),
(63, 20, 14),
(63, 219, 47),
(63, 375, 97),
(63, 423, 31),
(63, 488, 68),
(63, 498, 95),
(63, 580, 96),
(63, 627, 55),
(63, 650, 13),
(63, 726, 61),
(63, 777, 80),
(63, 803, 59),
(63, 886, 13),
(63, 945, 45),
(653, 130, 21), (653, 130, 21),
(653, 20, 93), (653, 20, 93),
(653, 232, 77), (653, 232, 77),
@ -692,16 +714,15 @@ INSERT INTO contenir VALUES
(653, 935, 17), (653, 935, 17),
(653, 945, 41), (653, 945, 41),
(653, 985, 16), (653, 985, 16),
(658, 130, 19),
(658, 133, 15),
(658, 210, 47),
(658, 375, 15),
(658, 501, 23),
(658, 734, 13),
(658, 921, 41),
(658, 935, 34),
(658, 13, 99), (658, 13, 99),
(658, 133, 76),
(658, 210, 83),
(658, 219, 12), (658, 219, 12),
(658, 334, 54),
(658, 355, 83),
(658, 36, 98),
(658, 488, 33),
(658, 559, 76),
(658, 650, 46), (658, 650, 46),
(658, 677, 72), (658, 677, 72),
(658, 726, 51), (658, 726, 51),
@ -709,48 +730,65 @@ INSERT INTO contenir VALUES
(658, 859, 96), (658, 859, 96),
(658, 900, 72), (658, 900, 72),
(658, 985, 56), (658, 985, 56),
(663, 233, 33),
(663, 288, 46),
(663, 304, 10),
(663, 488, 37),
(663, 797, 19),
(663, 133, 15),
(663, 210, 47),
(663, 501, 23),
(663, 734, 13),
(663, 921, 41),
(663, 935, 34),
(663, 219, 67), (663, 219, 67),
(663, 335, 66), (663, 335, 66),
(663, 355, 99), (663, 355, 99),
(663, 375, 90), (663, 375, 90),
(681, 13, 27), (663, 444, 63),
(681, 20, 26), (663, 498, 96),
(681, 253, 26), (663, 501, 31),
(681, 606, 13), (663, 580, 34),
(681, 777, 10), (663, 606, 51),
(681, 985, 12), (663, 686, 41),
(663, 726, 63),
(663, 734, 12),
(663, 859, 60),
(663, 900, 15),
(663, 921, 47),
(681, 133, 74), (681, 133, 74),
(681, 183, 42), (681, 183, 42),
(681, 219, 29), (681, 219, 29),
(681, 288, 87), (681, 288, 87),
(681, 334, 100), (681, 334, 100),
(700, 233, 33), (681, 335, 49),
(700, 288, 46), (681, 355, 35),
(700, 304, 10), (681, 529, 79),
(700, 355, 50), (681, 709, 35),
(700, 488, 37), (681, 859, 32),
(700, 797, 19), (681, 900, 61),
(681, 985, 24),
(700, 130, 94), (700, 130, 94),
(700, 133, 33), (700, 133, 33),
(753, 233, 33), (700, 183, 77),
(753, 288, 46), (700, 304, 37),
(753, 304, 10), (700, 345, 79),
(753, 355, 50), (700, 466, 62),
(753, 488, 37), (700, 498, 70),
(753, 797, 19), (700, 501, 20),
(700, 559, 53),
(700, 571, 37),
(700, 606, 73),
(700, 627, 13),
(700, 776, 34),
(700, 859, 81),
(700, 900, 74),
(700, 945, 42),
(753, 13, 32), (753, 13, 32),
(753, 20, 95), (753, 20, 95),
(753, 219, 22),
(753, 233, 80),
(753, 253, 64),
(753, 355, 83),
(753, 36, 78),
(753, 423, 40),
(753, 466, 20),
(753, 488, 100),
(753, 529, 91),
(753, 606, 32),
(753, 686, 23),
(753, 734, 65),
(753, 797, 72),
(753, 803, 46),
(91, 233, 38), (91, 233, 38),
(91, 253, 38), (91, 253, 38),
(91, 288, 25), (91, 288, 25),
@ -763,21 +801,24 @@ INSERT INTO contenir VALUES
(91, 498, 40), (91, 498, 40),
(91, 650, 30), (91, 650, 30),
(91, 133, 53), (91, 133, 53),
(911, 130, 19), (911, 133, 80),
(911, 133, 15), (911, 219, 30),
(911, 210, 47), (911, 375, 83),
(911, 375, 15), (911, 423, 23),
(911, 501, 23), (911, 444, 62),
(911, 734, 13), (911, 466, 51),
(911, 921, 41), (911, 498, 40),
(911, 935, 34), (911, 529, 68),
(911, 13, 27), (911, 571, 36),
(911, 183, 18), (911, 580, 23),
(911, 20, 26), (911, 677, 28),
(911, 253, 26), (911, 726, 23),
(911, 606, 13), (911, 734, 58),
(911, 777, 10), (911, 777, 84),
(911, 985, 12), (911, 797, 57),
(911, 803, 82),
(911, 935, 39),
(911, 945, 50),
(984, 233, 38), (984, 233, 38),
(984, 253, 38), (984, 253, 38),
(984, 288, 25), (984, 288, 25),
@ -814,16 +855,6 @@ INSERT INTO enregistrer VALUES
(340, 93, 8), (340, 93, 8),
(63, 733, 4), (63, 733, 4),
(700, 751, 5), (700, 751, 5),
(538, 443, 1),
(753, 883, 1),
(911, 93, 1),
(63, 797, 1),
(134, 162, 1),
(240, 925, 1),
(309, 929, 1),
(538, 24, 1),
(566, 312, 1),
(700, 127, 1),
(993, 162, 7); (993, 162, 7);
INSERT INTO etre VALUES INSERT INTO etre VALUES

View File

@ -29,7 +29,7 @@ docker compose -f docker-compose.dev.yml up
Use the file `docker-compose.prod.yml` to start the app in production mode, it can be done using the following command : Use the file `docker-compose.prod.yml` to start the app in production mode, it can be done using the following command :
``` ```
docker compose -f docker-compose.prod.yml up docker compose -f docker-compose.dev.yml up
``` ```
@ -42,3 +42,4 @@ docker compose -f docker-compose.prod.yml up
2) `export $(grep -v '^#' back-end/.env.production | xargs)` and then `make`. 2) `export $(grep -v '^#' back-end/.env.production | xargs)` and then `make`.
### EOF ### EOF

View File

@ -156,24 +156,28 @@ const boxById: RequestHandler<{ id: string; }> = async (req, res) => {
res.render('box.ejs', { box }); res.render('box.ejs', { box });
}; };
const removeBoxFromMember : RequestHandler<{ id_box: string, id_member: string }> = async (req, res) => {
const id_box = parseInt(req.params.id_box);
const id_member = parseInt(req.params.id_member);
await boxService.removeBoxFromMember(id_box, id_member)
res.sendStatus(200);
}
const registerBox: RequestHandler = async (req, res, next) => { const registerBox: RequestHandler = async (req, res, next) => {
const id_box = parseInt(req.body.id_box); const id_box = parseInt(req.body.id_box);
const id_member = parseInt(req.body.id_member); const id_member = parseInt(req.body.id_member);
const quantity = parseInt(req.body.quantity); const quantity = parseInt(req.body.quantity);
if (isNaN(id_box) || isNaN(id_member) || isNaN(quantity))
next();
await boxService.registerBox(id_box, id_member, quantity); await boxService.registerBox(id_box, id_member, quantity);
res.redirect('/membres/byid/' + id_member); const memberEither = await memberService.getMember(id_member);
if (memberEither.hasRight) {
console.error(memberEither.right);
next();
return;
}
const member = memberEither.left;
const models = await modelService.getAllBuildableModels(member.id_member);
const boxes = await boxService.getBoxesFromMember(member.id_member);
const pieces = await getBuyedPiecesFromMember(member.id_member);
const allboxes = await boxService.getAllBoxes();
res.render('member.ejs', { member, models, boxes, pieces, allboxes });
}; };
const boxController = { const boxController = {
@ -185,8 +189,7 @@ const boxController = {
allBoxesFromDate, allBoxesFromDate,
boxById, boxById,
registerBox, registerBox,
boxRemovePieceById, boxRemovePieceById
removeBoxFromMember,
}; };
export default boxController; export default boxController;

View File

@ -12,8 +12,6 @@ boxRouter.post("/register", boxController.registerBox);
boxRouter.get("/:title", boxController.boxByTitle); boxRouter.get("/:title", boxController.boxByTitle);
boxRouter.post("/:title", boxController.boxAddPieces); boxRouter.post("/:title", boxController.boxAddPieces);
boxRouter.delete("/:id_box/:id_member", boxController.removeBoxFromMember);
boxRouter.delete("/byid/:id_box", boxController.boxRemovePieceById); boxRouter.delete("/byid/:id_box", boxController.boxRemovePieceById);
boxRouter.post("/byid/:id_box", boxController.boxAddPiecesById); boxRouter.post("/byid/:id_box", boxController.boxAddPiecesById);

View File

@ -126,12 +126,6 @@ const registerBox = async (id_box: number, id_member: number, quantity: number)
await client.query("INSERT INTO enregistrer VALUES($1, $2, $3);", [id_box, id_member, quantity]); await client.query("INSERT INTO enregistrer VALUES($1, $2, $3);", [id_box, id_member, quantity]);
} }
const removeBoxFromMember = async (id_box: number, id_member: number) => {
const client = new_client();
await client.query("DELETE FROM enregistrer WHERE id_boite=$1 AND id_membre=$2;", [id_box, id_member]);
}
const boxService = { const boxService = {
addPiecesToBox, addPiecesToBox,
getBox, getBox,
@ -140,7 +134,6 @@ const boxService = {
removePieceFromBox, removePieceFromBox,
registerBox, registerBox,
getBoxesFromMember, getBoxesFromMember,
removeBoxFromMember,
}; };
export default boxService; export default boxService;

View File

@ -6,11 +6,6 @@
font-family: sans-serif; font-family: sans-serif;
} }
button {
background-color: transparent;
cursor: pointer;
}
pre, code { pre, code {
font-family: monospace; font-family: monospace;
} }

View File

@ -9,30 +9,19 @@
</title> </title>
<%- include('partials/links.ejs') %> <%- include('partials/links.ejs') %>
<style> <style>
#box-register-form { #box-register-form {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
max-width: max(30vw, 60ch); max-width: max(30vw, 60ch);
margin: auto; margin: auto;
} }
#box-register-form select, #box-register-form select, #box-register-form input {
#box-register-form input {
padding: .5rem 1rem; padding: .5rem 1rem;
} }
</style>
i {
color: var(--bg);
}
</style>
<script>
function removeBox(id) {
fetch(window.location.origin + '/boxes/' + id + '/' + <%= member.id_member %>, {method: 'DELETE'}).then(r => window.location.reload());
}
</script>
</head> </head>
<body> <body>
@ -52,28 +41,25 @@
name: <%= member.name%> name: <%= member.name%>
</pre> </pre>
<h2>Liste des boites enregistrées</h2>
<h2>Enregistrer une boite</h2>
<form name="title" action="/boxes/register" id="box-register-form" method="POST"> <form name="title" action="/boxes/register" id="box-register-form" method="POST">
<input type="hidden" name="id_member" id="id_member" value="<%= member.id_member %>"> <input type="hidden" name="id_member" id="id_member" value="<%= member.id_member %>">
<label for="id_box">Nom de la boite</label> <label for="id_box">id de la boite</label>
<select name="id_box" id="id_box"> <select name="id_box" id="id_box">
<% allboxes.forEach(function(box) { %> <% allboxes.forEach(function(box) { %>
<option value="<%=box.id%>"> <option value="<%=box.id%>"><%=box.id%></option>
<%=box.title%>
</option>
<% }); %> <% }); %>
</select> </select>
<label for="quantity">Quantité</label> <label for="quantity">Quantité</label>
<input type="number" name="quantity" min="1" step="1" id="quantity" value="1"> <input type="number" name="quantity" min="0" step="1" id="quantity">
<input type="submit" value="Ajouter"> <input type="submit" value="Ajouter">
</form> </form>
<h2>Liste des boites enregistrées</h2>
<div class="table"> <div class="table">
<table> <table>
<thead> <thead>
@ -83,7 +69,6 @@
<th>Nombre de pièces</th> <th>Nombre de pièces</th>
<th>Quantité</th> <th>Quantité</th>
<th></th> <th></th>
<th></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -102,7 +87,6 @@
<%=box.second%> <%=box.second%>
</td> </td>
<td><a href="/boxes/byid/<%=box.first.id%>"><i class="fa-solid fa-eye"></i></a></td> <td><a href="/boxes/byid/<%=box.first.id%>"><i class="fa-solid fa-eye"></i></a></td>
<td><button onclick="removeBox(<%=box.first.id%>)"><i class="fa-solid fa-trash"></i></button></td>
</tr> </tr>
<% }); %> <% }); %>
@ -174,26 +158,19 @@
<td> <td>
<%=model.name%> <%=model.name%>
</td> </td>
<% if (model.creator===undefined) {%> <td><a href="/membres/byid/<%=model.creator%>"><i class="fa-solid fa-user"></i>
<%=model.creator%>
<td></td>
<% } else {%>
<td><a href="/membres/byid/<%=model.creator.id_member%>"><i class="fa-solid fa-user"></i>
<%=model.creator.name%>
</a></td> </a></td>
<% } %>
<td><a href="/models/byname/<%=model.name%>"><i class="fa-solid fa-eye"></i></a></td> <td><a href="/models/byname/<%=model.name%>"><i class="fa-solid fa-eye"></i></a></td>
</tr> </tr>
<% }); %> <% }); %>
</tbody> </tbody>
</table> </table>
<div class="box"></div> <div class="box"></div>
</div> </div>
</main> </main>
</body> </body>
</html> </html>

View File

@ -23,7 +23,7 @@
id : <%= model.id %> id : <%= model.id %>
url : <%= model.url %> url : <%= model.url %>
creator : <%- model.creator !== undefined ? model.creator.name : 'system' %> creator : <%= model.creator.name %>
inheritFrom : <%= model.inheritFrom %> inheritFrom : <%= model.inheritFrom %>
<h2>Liste des pièces nécessaires</h2> <h2>Liste des pièces nécessaires</h2>
<div class="table"> <div class="table">

View File

@ -32,23 +32,10 @@
<tbody> <tbody>
<% models.forEach(function(model) { %> <% models.forEach(function(model) { %>
<tr> <tr>
<td> <td><%=model.id%></td>
<%=model.id%> <td><%=model.name%></td>
</td> <td><a href="/membres/byid/<%=model.creator.id_member%>"><i class="fa-solid fa-user"></i> <%=model.creator.name%></a></td>
<td> <td><%=model.review.first%>/5 (<%=model.review.second%> avis)</td>
<%=model.name%>
</td>
<% if (model.creator===undefined) {%>
<td></td>
<% } else {%>
<td><a href="/membres/byid/<%=model.creator.id_member%>"><i class="fa-solid fa-user"></i>
<%=model.creator.name%>
</a></td>
<% } %>
<td>
<%=model.review.first%>/5 (<%=model.review.second%> avis)
</td>
<td><a href="/models/byname/<%=model.name%>"><i class="fa-solid fa-eye"></i></a></td> <td><a href="/models/byname/<%=model.name%>"><i class="fa-solid fa-eye"></i></a></td>
</tr> </tr>

View File

@ -6,7 +6,7 @@ type Model = {
id: number; id: number;
name: string; name: string;
url: string; url: string;
creator: Member | undefined; creator: Member;
inheritFrom: number; inheritFrom: number;
pieces: Array<Pair<Piece, number>> pieces: Array<Pair<Piece, number>>
review: Pair<number, number> review: Pair<number, number>