feat: add models per box
This commit is contained in:
parent
08dcfa2e88
commit
e96ff1621c
@ -1,8 +1,10 @@
|
|||||||
import { new_client } from '../db/db_client';
|
import { new_client } from '../db/db_client';
|
||||||
import { Box } from '../types/box';
|
import { Box } from '../types/box';
|
||||||
|
import { Model } from '../types/model';
|
||||||
import { Piece } from '../types/piece';
|
import { Piece } from '../types/piece';
|
||||||
import { getPiece } from './pieces.service';
|
import { getPiece } from './pieces.service';
|
||||||
import { Either, eitherLeft, eitherRight, Pair, createPair } from '../utils/utils';
|
import { Either, eitherLeft, eitherRight, Pair, createPair } from '../utils/utils';
|
||||||
|
import modelService from './model.service';
|
||||||
|
|
||||||
type DBBox = {
|
type DBBox = {
|
||||||
id_boite: number;
|
id_boite: number;
|
||||||
@ -33,11 +35,25 @@ async function removePieceFromBox(id_box: number, id_piece: number) {
|
|||||||
const res = await client.query(`DELETE FROM contenir WHERE id_boite = $1 AND id_piece = $2;`, [ id_box, id_piece ]);
|
const res = await client.query(`DELETE FROM contenir WHERE id_boite = $1 AND id_piece = $2;`, [ id_box, id_piece ]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getModelsFromBox(id_box: number): Promise<Array<Model>> {
|
||||||
|
const client = new_client();
|
||||||
|
const res = await client.query(`SELECT * FROM modeles_faisables_boite($1);`, [ id_box ]);
|
||||||
|
const arr: Array<Model> = new Array();
|
||||||
|
for (let i = 0; i < res.rows.length; ++i) {
|
||||||
|
const model: Either<Model, string> = await modelService.getModel(res.rows[i]['id_model']);
|
||||||
|
if (model.hasRight)
|
||||||
|
continue;
|
||||||
|
arr.push(model.left);
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
async function db2box(data: DBBox): Promise<Box> {
|
async function db2box(data: DBBox): Promise<Box> {
|
||||||
const box: Box = {
|
const box: Box = {
|
||||||
id: data.id_boite,
|
id: data.id_boite,
|
||||||
title: data.titre_boite,
|
title: data.titre_boite,
|
||||||
date: new Date(data.date_boite),
|
date: new Date(data.date_boite),
|
||||||
|
models: await getModelsFromBox(data.id_boite),
|
||||||
pieces: await getPiecesFromBox(data.id_boite)
|
pieces: await getPiecesFromBox(data.id_boite)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -25,6 +25,14 @@ function deletePiece(id) {
|
|||||||
<pre>
|
<pre>
|
||||||
id : <%= box.id %>
|
id : <%= box.id %>
|
||||||
date : <%= box.date %>
|
date : <%= box.date %>
|
||||||
|
modèles :
|
||||||
|
<% box.models.forEach(function(m) { %>
|
||||||
|
<li>
|
||||||
|
<a href="/models/byid/<%=m.id_id_model%>">
|
||||||
|
<%=m.id_name%>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<% }); %>
|
||||||
pièces :
|
pièces :
|
||||||
<% box.pieces.forEach(function(pair) { %>
|
<% box.pieces.forEach(function(pair) { %>
|
||||||
<li>
|
<li>
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { Model } from './model';
|
||||||
import { Pair } from '../utils/utils';
|
import { Pair } from '../utils/utils';
|
||||||
import { Piece } from './piece';
|
import { Piece } from './piece';
|
||||||
|
|
||||||
@ -5,7 +6,8 @@ type Box = {
|
|||||||
id: number;
|
id: number;
|
||||||
title: string;
|
title: string;
|
||||||
date: Date;
|
date: Date;
|
||||||
pieces: Array<Pair<Piece, number>>
|
models: Array<Model>;
|
||||||
|
pieces: Array<Pair<Piece, number>>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export { Box };
|
export { Box };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user