feat: add pieces per box
This commit is contained in:
parent
f4d7d9be41
commit
16e6b04e66
2
Makefile
2
Makefile
@ -6,7 +6,7 @@ all: build
|
||||
build: dev
|
||||
|
||||
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:
|
||||
. $(DIR_BACK)/.env && docker-compose -f docker-compose.prod.yml up
|
||||
|
@ -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 arr: Array<Pair<Piece, number>> = new Array();
|
||||
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']);
|
||||
console.log(piece);
|
||||
if (piece.hasRight)
|
||||
continue;
|
||||
arr.push(createPair(piece.left, res.rows[i]['quantite_contenir'] as number));
|
||||
|
@ -12,7 +12,7 @@ async function getEntity<T>(table: string, column: string, value: string | numbe
|
||||
}
|
||||
const entity: T = f(res.rows[0]);
|
||||
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>> {
|
||||
@ -87,10 +87,11 @@ async function createShape(name: string): Promise<Shape> {
|
||||
async function getPiece(id: number): Promise<Either<Piece, string>> {
|
||||
const client = new_client();
|
||||
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]) {
|
||||
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]) };
|
||||
return eitherLeft<Piece, string>(result);
|
||||
}
|
||||
@ -98,7 +99,7 @@ async function getPiece(id: number): Promise<Either<Piece, string>> {
|
||||
async function getPieces(): Promise<Array<Piece>> {
|
||||
const client = new_client();
|
||||
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();
|
||||
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]) });
|
||||
|
@ -19,6 +19,14 @@
|
||||
<pre>
|
||||
id : <%= box.id %>
|
||||
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>
|
||||
</body>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user