feat: add get all models from fans

This commit is contained in:
Nemo D'ACREMONT 2024-11-27 15:12:52 +01:00
parent 502718929a
commit b297b88c64
No known key found for this signature in database
GPG Key ID: 6E5BCE8022FA8276
4 changed files with 28 additions and 2 deletions

View File

@ -33,10 +33,17 @@ const modelById: RequestHandler<{ id: string; }> = async (req, res) => {
res.render('model.ejs', { model });
};
const allModelsFromFans: RequestHandler = async (req, res) => {
const models = await modelService.getAllModelsFromFans();
res.render('models.ejs', { models });
};
const modelController = {
modelByName,
allModels,
modelById,
allModelsFromFans,
};
export default modelController;

View File

@ -5,7 +5,9 @@ const modelRouter = express.Router();
modelRouter.get("/", modelController.allModels);
modelRouter.get("/:name", modelController.modelByName);
modelRouter.get("/byname/:name", modelController.modelByName);
modelRouter.get("/fromfan", modelController.allModelsFromFans);
modelRouter.get("/byid/:id", modelController.modelById);

View File

@ -44,7 +44,21 @@ const getModel = async (idOrName: number | string): Promise<Either<Model, string
const getAllModels = async () => {
const client = new_client();
await client.connect();
const res = await client.query("SELECT * FROM modeles");
await client.end();
return res.rows.map(db2Model);
}
const getAllModelsFromFans = async () => {
const client = new_client();
await client.connect();
const res = await client.query(
"SELECT id_modele FROM modeles WHERE id_membre IS NOT NULL"
);
await client.end();
return res.rows.map(db2Model);
}
@ -76,6 +90,7 @@ const modelService = {
getModel,
getAllModels,
createModel,
getAllModelsFromFans,
};
export default modelService;

View File

@ -12,6 +12,8 @@
<body>
<%- include('partials/header.ejs') %>
<a href="/models/fromfan"><p>Liste des modèles proposés par des fans</p></a>
<h1>
Liste des modeles
</h1>
@ -19,7 +21,7 @@
<ul>
<% models.forEach(function(model) { %>
<li>
<a href="/models/<%=model.name%>">
<a href="/models/byname/<%=model.name%>">
<%=model.name%>
</a>
</li>