diff --git a/apps/server/src/controllers/admin/logs.js b/apps/server/src/controllers/admin/logs.js new file mode 100644 index 000000000..1a022162a --- /dev/null +++ b/apps/server/src/controllers/admin/logs.js @@ -0,0 +1,16 @@ +import { adminGroupPath } from 'shared/src/utils/const.js' +import { sendForbidden, sendNotFound, sendOk } from '../../utils/response.js' +import { getAllLogs } from '../../models/queries/log-queries.js' + +export const getLogsController = async (req, res) => { + if (!req.session.user.groups?.includes(adminGroupPath)) sendForbidden(res, 'Vous n\'avez pas les droits administrateur') + + try { + const logs = await getAllLogs() + + sendOk(res, logs) + } catch (error) { + const description = 'Echec de la récupération des organisations' + sendNotFound(res, description) + } +} diff --git a/apps/server/src/routes/admin/index.js b/apps/server/src/routes/admin/index.js index 51002470a..8ac5c35ab 100644 --- a/apps/server/src/routes/admin/index.js +++ b/apps/server/src/routes/admin/index.js @@ -1,5 +1,6 @@ import userRouter from './user.js' import organizationRouter from './organization.js' +import logRouter from './log.js' const router = async (app, _opt) => { // Enregistrement du sous routeur user @@ -7,6 +8,9 @@ const router = async (app, _opt) => { // Enregistrement du sous routeur organization await app.register(organizationRouter, { prefix: '/organizations' }) + + // Enregistrement du sous routeur logd + await app.register(logRouter, { prefix: '/log' }) } export default router diff --git a/apps/server/src/routes/admin/log.js b/apps/server/src/routes/admin/log.js new file mode 100644 index 000000000..5a8ccae66 --- /dev/null +++ b/apps/server/src/routes/admin/log.js @@ -0,0 +1,8 @@ +import { getLogsController } from '../../controllers/admin/logs.js' + +const router = async (app, _opt) => { + // Récupérer toutes les organisations + await app.get('/', getLogsController) +} + +export default router