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 }); res.render('model.ejs', { model });
}; };
const allModelsFromFans: RequestHandler = async (req, res) => {
const models = await modelService.getAllModelsFromFans();
res.render('models.ejs', { models });
};
const modelController = { const modelController = {
modelByName, modelByName,
allModels, allModels,
modelById, modelById,
allModelsFromFans,
}; };
export default modelController; export default modelController;

View File

@ -5,7 +5,9 @@ const modelRouter = express.Router();
modelRouter.get("/", modelController.allModels); 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); 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 getAllModels = async () => {
const client = new_client(); const client = new_client();
await client.connect(); await client.connect();
const res = await client.query("SELECT * FROM modeles"); 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(); await client.end();
return res.rows.map(db2Model); return res.rows.map(db2Model);
} }
@ -76,6 +90,7 @@ const modelService = {
getModel, getModel,
getAllModels, getAllModels,
createModel, createModel,
getAllModelsFromFans,
}; };
export default modelService; export default modelService;

View File

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