feat: add pieces per box
This commit is contained in:
parent
f4d7d9be41
commit
16e6b04e66
@ -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));
|
||||||
|
@ -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]) });
|
||||||
|
@ -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>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user