Skip to content

Commit

Permalink
feat: ✨ log api endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudTA committed Jun 5, 2023
1 parent c346f6e commit 17985ff
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
16 changes: 16 additions & 0 deletions apps/server/src/controllers/admin/logs.js
Original file line number Diff line number Diff line change
@@ -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)
}
}
4 changes: 4 additions & 0 deletions apps/server/src/routes/admin/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
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
await app.register(userRouter, { prefix: '/users' })

// 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
8 changes: 8 additions & 0 deletions apps/server/src/routes/admin/log.js
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 17985ff

Please sign in to comment.