Skip to content

Logs


Log CRUD Operations


1. Create Log - POST /api/v1/logs

  • Description: This endpoint allows admins to manually create a log entry for actions performed in the system, such as creating or deleting users, updating venues, etc.

  • Parameters:

  • action: The type of action performed (e.g., "User Created", "Venue Updated", "User Deleted").
  • userId: The ID of the user who performed the action.
  • details: A description of the action performed (optional).
  • timestamp: The timestamp of when the action occurred (auto-generated).

  • Request Body:

{
  "action": "User Created",
  "userId": "admin123",
  "details": "Admin user created a new employee user account with email godbless.nyagawa@example.com"
}
  • Response:
{
  "status": "success",
  "message": "Log created successfully.",
  "data": {
    "_id": "log_id_1",
    "action": "User Created",
    "userId": "admin123",
    "details": "Admin user created a new employee user account with email godbless.nyagawa@example.com",
    "timestamp": "2025-02-17T12:00:00.000Z"
  }
}
  • Response Codes:
  • 201 CREATED: Log successfully created.
  • 400 BAD REQUEST: Missing or invalid fields in the request.

2. Get All Logs - GET /api/v1/logs

  • Description: Retrieve a list of all logs in the system.

  • Response:

[
  {
    "_id": "log_id_1",
    "action": "User Created",
    "userId": "admin123",
    "details": "Admin user created a new employee user account with email godbless.nyagawa@example.com",
    "timestamp": "2025-02-17T12:00:00.000Z"
  },
  {
    "_id": "log_id_2",
    "action": "Venue Updated",
    "userId": "admin123",
    "details": "Admin updated the capacity of Conference Hall A to 350",
    "timestamp": "2025-02-17T12:05:00.000Z"
  }
]
  • Response Codes:
  • 200 OK: Returns the list of logs.
  • 204 No Content: If no logs are available.

3. Get Log by ID - GET /api/v1/logs/:id

  • Description: Retrieve a specific log by its ID.

  • Response:

{
  "_id": "log_id_1",
  "action": "User Created",
  "userId": "admin123",
  "details": "Admin user created a new employee user account with email godbless.nyagawa@example.com",
  "timestamp": "2025-02-17T12:00:00.000Z"
}
  • Response Codes:
  • 200 OK: Returns the log by its ID.
  • 404 NOT FOUND: If the log with the given ID is not found.

4. Update Log - PUT /api/v1/logs/:id

  • Description: Allows an admin to update a specific log entry, though this is less common since logs are typically immutable. This operation might be used for minor corrections or updates (e.g., fixing a typo in the details).

  • Parameters:

  • action: The type of action performed (optional).
  • userId: The ID of the user who performed the action (optional).
  • details: A description of the action performed (optional).

  • Request Body:

{
  "details": "Admin user created a new employee user account with email jane.smith@example.com"
}
  • Response:
{
  "status": "success",
  "message": "Log updated successfully.",
  "data": {
    "_id": "log_id_1",
    "action": "User Created",
    "userId": "admin123",
    "details": "Admin user created a new employee user account with email jane.smith@example.com",
    "timestamp": "2025-02-17T12:00:00.000Z"
  }
}
  • Response Codes:
  • 200 OK: Log successfully updated.
  • 404 NOT FOUND: If the log with the given ID does not exist.
  • 400 BAD REQUEST: If any invalid data is passed.

5. Delete Log - DELETE /api/v1/logs/:id

  • Description: Allows an admin to delete a specific log by its ID. However, logs are typically kept for auditing purposes and may not be deleted in some systems.

  • Response:

{
  "status": "success",
  "message": "Log deleted successfully."
}
  • Response Codes:
  • 200 OK: Log successfully deleted.
  • 404 NOT FOUND: If the log with the given ID is not found.

6. Get Total Log Count - GET /api/v1/logs-total

  • Description: Retrieves the total number of logs in the system.

  • Response:

{
  "totalCount": 10
}
  • Response Codes:
  • 200 OK: Successfully returns the total count of logs.
  • 204 No Content: If no logs exist.

Example Flow for Log Operations:

  1. Admin creates a log entry:
  2. POST /api/v1/logs with the action details.
  3. Response: Log entry created successfully.

  4. Get all logs:

  5. GET /api/v1/logs.
  6. Response: List of all logs.

  7. Get a specific log:

  8. GET /api/v1/logs/:id.
  9. Response: Details of the log.

  10. Update a log:

  11. PUT /api/v1/logs/:id with updated details.
  12. Response: Log updated successfully.

  13. Delete a log:

  14. DELETE /api/v1/logs/:id.
  15. Response: Log deleted successfully.

  16. Get total log count:

  17. GET /api/v1/logs-total.
  18. Response: Returns the total count of logs.

Security & Validation Notes

  • Make sure to authenticate and authorize the user making the request to access the logs, especially when dealing with log management.
  • Logs should generally not be altered once created, so consider limiting update and delete operations to admins only.
  • Consider adding additional filters for log retrieval, like filtering by user, action type, or time range to make logs more useful.