feat: add pieces per box

This commit is contained in:
Alessandre Laguierce 2024-12-02 14:20:38 +01:00
parent f4d7d9be41
commit 16e6b04e66
4 changed files with 15 additions and 4 deletions

View File

@ -6,7 +6,7 @@ all: build
build: dev build: dev
dev: $(DIR_BACK)/.env dev: $(DIR_BACK)/.env
. $(DIR_BACK)/.env && docker-compose -f docker-compose.dev.yml up . $(DIR_BACK)/.env && docker-compose -f docker-compose.dev.yml up
prod: prod:
. $(DIR_BACK)/.env && docker-compose -f docker-compose.prod.yml up . $(DIR_BACK)/.env && docker-compose -f docker-compose.prod.yml up

View File

@ -16,7 +16,9 @@ async function getPiecesFromBox(id_box: number): Promise<Array<Pair<Piece, numbe
const res = await client.query(`SELECT * FROM contenir WHERE id_boite = $1;`, [ id_box ]); const res = await client.query(`SELECT * FROM contenir WHERE id_boite = $1;`, [ id_box ]);
const arr: Array<Pair<Piece, number>> = new Array(); const arr: Array<Pair<Piece, number>> = new Array();
for (let i = 0; i < res.rows.length; ++i) { for (let i = 0; i < res.rows.length; ++i) {
console.log(res.rows[i]['id_piece']);
const piece: Either<Piece, string> = await getPiece(res.rows[i]['id_piece']); const piece: Either<Piece, string> = await getPiece(res.rows[i]['id_piece']);
console.log(piece);
if (piece.hasRight) if (piece.hasRight)
continue; continue;
arr.push(createPair(piece.left, res.rows[i]['quantite_contenir'] as number)); arr.push(createPair(piece.left, res.rows[i]['quantite_contenir'] as number));

View File

@ -12,7 +12,7 @@ async function getEntity<T>(table: string, column: string, value: string | numbe
} }
const entity: T = f(res.rows[0]); const entity: T = f(res.rows[0]);
await client.end(); await client.end();
return eitherLeft<T, string>(entity); return eitherLeft<T, string>(entity);
} }
async function getEntities<T>(table: string, f: (o: Object) => T): Promise<Array<T>> { async function getEntities<T>(table: string, f: (o: Object) => T): Promise<Array<T>> {
@ -87,10 +87,11 @@ async function createShape(name: string): Promise<Shape> {
async function getPiece(id: number): Promise<Either<Piece, string>> { async function getPiece(id: number): Promise<Either<Piece, string>> {
const client = new_client(); const client = new_client();
await client.connect(); await client.connect();
const res = await client.query(`SELECT * FROM pieces NATURAL JOIN colorer NATURAL JOIN etre_forme NATURAL JOIN avoir_motif WHERE id_piece = $1`, [id]); const res = await client.query(`SELECT * FROM pieces NATURAL JOIN colorer NATURAL JOIN couleurs NATURAL JOIN etre_forme NATURAL JOIN formes NATURAL JOIN avoir_motif NATURAL JOIN motifs WHERE id_piece = $1`, [id]);
if (!res.rows[0]) { if (!res.rows[0]) {
return eitherRight<Piece, string>("Nothing found"); return eitherRight<Piece, string>("Nothing found");
} }
console.log(`Get entity ${Object.keys(res.rows[0])}`);
const result: Piece = { id_piece: res.rows[0]['id_piece'], colour: toColour(res.rows[0]), pattern: toPattern(res.rows[0]), shape: toShape(res.rows[0]) }; const result: Piece = { id_piece: res.rows[0]['id_piece'], colour: toColour(res.rows[0]), pattern: toPattern(res.rows[0]), shape: toShape(res.rows[0]) };
return eitherLeft<Piece, string>(result); return eitherLeft<Piece, string>(result);
} }
@ -98,7 +99,7 @@ async function getPiece(id: number): Promise<Either<Piece, string>> {
async function getPieces(): Promise<Array<Piece>> { async function getPieces(): Promise<Array<Piece>> {
const client = new_client(); const client = new_client();
await client.connect(); await client.connect();
const res = await client.query(`SELECT * FROM pieces NATURAL JOIN colorer NATURAL JOIN etre_forme NATURAL JOIN avoir_motif;`); const res = await client.query(`SELECT * FROM pieces NATURAL JOIN colorer NATURAL JOIN couleurs NATURAL JOIN etre_forme NATURAL JOIN formes NATURAL JOIN avoir_motif NATURAL JOIN motifs;`);
const arr: Array<Piece> = new Array(); const arr: Array<Piece> = new Array();
for (let i = 0; i < res.rows.length; ++i) { for (let i = 0; i < res.rows.length; ++i) {
arr.push({ id_piece: res.rows[i]['id_piece'], colour: toColour(res.rows[i]), pattern: toPattern(res.rows[i]), shape: toShape(res.rows[i]) }); arr.push({ id_piece: res.rows[i]['id_piece'], colour: toColour(res.rows[i]), pattern: toPattern(res.rows[i]), shape: toShape(res.rows[i]) });

View File

@ -19,6 +19,14 @@
<pre> <pre>
id : <%= box.id %> id : <%= box.id %>
date : <%= box.date %> date : <%= box.date %>
pièces :
<% box.pieces.forEach(function(pair) { console.log(pair);%>
<li>
<a href="/pieces/<%=pair.first.id_piece%>">
<%=pair.first.id_piece%> @ <%=pair.second%>
</a>
</li>
<% }); %>
</pre> </pre>
</body> </body>