Maintainers
Pricing
Enterprise
More
More
Documentation
Try Live
Rankings
Install
Blog
Docs7
Ask
New
Add Docs
Helping Wizard Backend
https://github.com/helpingwizard/backend-repo
Admin
Tokens:
4,661
Snippets:
43
Trust Score:
5.6
Update:
1 year ago
Context
Chat
Benchmark
Latest
Show doc for...
Code
Info
Show Results
Tokens:
Raw
Copy
Link
Tokens:
Raw
Copy
Link
### Example API Calls using cURL Source: https://github.com/helpingwizard/backend-repo/blob/main/API_DOCUMENTATION.md Demonstrates how to interact with various API endpoints (registration, login, event creation, event retrieval) using cURL commands. These examples illustrate sending JSON payloads and including authorization headers for protected routes. ```bash # Register a new user curl -X POST http://localhost:3000/api/auth/register \ -H "Content-Type: application/json" \ -d '{"email":"user@example.com","password":"password123","name":"John Doe"}' # Login curl -X POST http://localhost:3000/api/auth/login \ -H "Content-Type: application/json" \ -d '{"email":"user@example.com","password":"password123"}' # Create an event (admin only) curl -X POST http://localhost:3000/api/events \ -H "Authorization: Bearer <your_token>" \ -H "Content-Type: application/json" \ -d '{"title":"Annual Meeting","description":"Yearly gathering","date":"2024-12-31T18:00:00Z","location":"Main Hall","capacity":100}' # Get all events curl -X GET http://localhost:3000/api/events \ -H "Authorization: Bearer <your_token>" ``` -------------------------------- ### Start Backend Development Server Source: https://github.com/helpingwizard/backend-repo/blob/main/README.md Command to start the Node.js development server, making the API accessible locally. ```Bash npm run dev ``` -------------------------------- ### Install Node.js Dependencies Source: https://github.com/helpingwizard/backend-repo/blob/main/README.md Command to install all required Node.js project dependencies using npm. ```Bash npm install ``` -------------------------------- ### Example API Calls using JavaScript/TypeScript Fetch API Source: https://github.com/helpingwizard/backend-repo/blob/main/API_DOCUMENTATION.md Provides JavaScript/TypeScript examples demonstrating how to make API calls for user login and retrieving events using the `fetch` API. These snippets show how to handle headers, JSON request bodies, and parse JSON responses. ```typescript // Example using fetch const API_URL = 'http://localhost:3000/api'; async function login(email: string, password: string) { const response = await fetch(`${API_URL}/auth/login`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ email, password }), }); const data = await response.json(); return data; } async function getEvents(token: string) { const response = await fetch(`${API_URL}/events`, { headers: { 'Authorization': `Bearer ${token}`, }, }); const data = await response.json(); return data; } ``` -------------------------------- ### Copy Environment Variable Example File Source: https://github.com/helpingwizard/backend-repo/blob/main/README.md Command to copy the provided .env.example file to create a new .env file for local configuration. ```Bash cp .env.example .env ``` -------------------------------- ### Configure Backend Environment Variables Source: https://github.com/helpingwizard/backend-repo/blob/main/README.md Example configuration for the .env file, specifying the PostgreSQL database connection URL, a JWT secret key for authentication, and the server's listening port. ```env DATABASE_URL="postgresql://username:password@localhost:5432/pasc_cca_2025" JWT_SECRET="your-secret-key" PORT=3000 ``` -------------------------------- ### Get All Events API Endpoint Source: https://github.com/helpingwizard/backend-repo/blob/main/API_DOCUMENTATION.md Retrieves a paginated list of all events. Supports optional query parameters for pagination, searching by title/description, and filtering by date. ```APIDOC GET /events Query Parameters: - `page` (optional): Page number for pagination - `limit` (optional): Number of items per page - `search` (optional): Search term for event title/description - `date` (optional): Filter by date (ISO format) Response: { "success": true, "data": { "events": [ { "id": "string", "title": "string", "description": "string", "date": "string", "location": "string", "capacity": "number", "createdAt": "string", "updatedAt": "string" } ], "pagination": { "total": "number", "page": "number", "limit": "number", "pages": "number" } } } ``` -------------------------------- ### Get Events Created by Admin API Endpoint (Admin Only) Source: https://github.com/helpingwizard/backend-repo/blob/main/API_DOCUMENTATION.md Retrieves a list of events that have been created by the current administrator. ```APIDOC GET /events/admin Response: { "success": true, "data": [ { "id": "string", "title": "string", "description": "string", "date": "string", "location": "string", "capacity": "number", "createdAt": "string", "updatedAt": "string" } ] } ``` -------------------------------- ### Prisma Schema for AttendanceSession Model Source: https://github.com/helpingwizard/backend-repo/blob/main/README.md Defines the AttendanceSession model in Prisma, specifying the start and end times for an attendance period, and linking to the administering admin, the associated event, and individual attendance records. ```Prisma model AttendanceSession { id Int @id @default(autoincrement()) startTime DateTime endTime DateTime createdAt DateTime @default(now()) updatedAt DateTime @updatedAt admin Admin @relation(fields: [adminId], references: [id]) adminId Int event Event @relation(fields: [eventId], references: [id]) eventId Int attendances Attendance[] } ``` -------------------------------- ### Get Event by ID API Endpoint Source: https://github.com/helpingwizard/backend-repo/blob/main/API_DOCUMENTATION.md Retrieves the detailed information for a specific event using its unique identifier. ```APIDOC GET /events/:id Response: { "success": true, "data": { "id": "string", "title": "string", "description": "string", "date": "string", "location": "string", "capacity": "number", "createdAt": "string", "updatedAt": "string" } } ``` -------------------------------- ### Get Current User API Endpoint Source: https://github.com/helpingwizard/backend-repo/blob/main/API_DOCUMENTATION.md Retrieves the profile details of the currently authenticated user. This endpoint requires a valid JWT token. ```APIDOC GET /auth/me Response: { "success": true, "data": { "id": "string", "email": "string", "name": "string", "role": "string" } } ``` -------------------------------- ### Get Event Attendance List API Endpoint (Admin Only) Source: https://github.com/helpingwizard/backend-repo/blob/main/API_DOCUMENTATION.md Retrieves a detailed attendance list for a specific event, including session-wise attendance counts. This endpoint is restricted to admin users and provides an overview of event participation. ```APIDOC GET /events/:eventId/attendance Response: { "success": true, "data": { "eventId": "string", "totalSessions": "number", "totalAttendees": "number", "sessions": [ { "sessionId": "string", "startTime": "string", "endTime": "string", "attendees": "number" } ] } } ``` -------------------------------- ### Clone Backend Repository Source: https://github.com/helpingwizard/backend-repo/blob/main/README.md Instructions to clone the PASC CCA Backend 2025 repository from GitHub and navigate into its directory. ```Bash git clone https://github.com/PICT-ACM-Student-Chapter/PASC-CCA-Backend_2025.git cd PASC-CCA-Backend_2025 ``` -------------------------------- ### Recommended API Best Practices for Clients Source: https://github.com/helpingwizard/backend-repo/blob/main/API_DOCUMENTATION.md Provides a list of essential best practices for client applications interacting with the API. These guidelines cover security, error handling, performance optimization, and general usage recommendations to ensure robust integration. ```APIDOC 1. Always include the `Authorization` header for protected endpoints 2. Handle rate limiting by implementing exponential backoff 3. Validate request data before sending 4. Handle all possible error responses 5. Use HTTPS in production 6. Store tokens securely and never expose them in client-side code ``` -------------------------------- ### Run Prisma Database Migrations Source: https://github.com/helpingwizard/backend-repo/blob/main/README.md Command to apply Prisma database migrations, setting up the necessary tables and schema in the PostgreSQL database. ```Bash npx prisma migrate dev ``` -------------------------------- ### Create PostgreSQL Database Source: https://github.com/helpingwizard/backend-repo/blob/main/README.md Command to create the PostgreSQL database instance named 'pasc_cca_2025' required by the backend application. ```Bash createdb pasc_cca_2025 ``` -------------------------------- ### Register New User API Endpoint Source: https://github.com/helpingwizard/backend-repo/blob/main/API_DOCUMENTATION.md Registers a new user account in the system. Requires email, password, and name in the request body. Returns a JWT token and user details upon successful registration. ```APIDOC POST /auth/register Request Body: { "email": "string", "password": "string", "name": "string" } Response: { "success": true, "data": { "token": "string", "user": { "id": "string", "email": "string", "name": "string", "role": "user" } } } ``` -------------------------------- ### API Base URL Source: https://github.com/helpingwizard/backend-repo/blob/main/API_DOCUMENTATION.md The foundational URL for all API requests within the PASC CCA 2025 system. ```HTTP http://localhost:3000/api ``` -------------------------------- ### Create New Event API Endpoint (Admin Only) Source: https://github.com/helpingwizard/backend-repo/blob/main/API_DOCUMENTATION.md Allows administrators to create a new event. Requires event details such as title, description, date, location, and capacity in the request body. ```APIDOC POST /events Request Body: { "title": "string", "description": "string", "date": "string (ISO date)", "location": "string", "capacity": "number" } Response: { "success": true, "data": { "id": "string", "title": "string", "description": "string", "date": "string", "location": "string", "capacity": "number", "createdAt": "string", "updatedAt": "string" } } ``` -------------------------------- ### User Login API Endpoint Source: https://github.com/helpingwizard/backend-repo/blob/main/API_DOCUMENTATION.md Authenticates a user with their email and password. Upon successful authentication, a JWT token and user details are returned. ```APIDOC POST /auth/login Request Body: { "email": "string", "password": "string" } Response: { "success": true, "data": { "token": "string", "user": { "id": "string", "email": "string", "name": "string", "role": "string" } } } ``` -------------------------------- ### Backend API Authentication Endpoints Source: https://github.com/helpingwizard/backend-repo/blob/main/README.md Lists the API endpoints for user and admin registration and login, enabling secure access to the system. ```APIDOC POST /api/auth/user/register - Register a new user POST /api/auth/user/login - User login POST /api/auth/admin/register - Register a new admin POST /api/auth/admin/login - Admin login ``` -------------------------------- ### Prisma Schema for Event Model Source: https://github.com/helpingwizard/backend-repo/blob/main/README.md Defines the Event model in Prisma, detailing event properties such as title, description, date, location, and capacity, and establishing relations to the creating admin, RSVPs, and attendance sessions. ```Prisma model Event { id Int @id @default(autoincrement()) title String description String date DateTime location String capacity Int createdAt DateTime @default(now()) updatedAt DateTime @updatedAt admin Admin @relation(fields: [adminId], references: [id]) adminId Int rsvps Rsvp[] sessions AttendanceSession[] } ``` -------------------------------- ### Backend API Attendance Management Endpoints Source: https://github.com/helpingwizard/backend-repo/blob/main/README.md Lists the API endpoints for creating attendance sessions and marking/retrieving attendance. Creating sessions is restricted to admin users. ```APIDOC POST /api/events/:id/sessions - Create attendance session (Admin only) POST /api/sessions/:id/attendance - Mark attendance GET /api/sessions/:id/attendance - Get attendance for a session ``` -------------------------------- ### API Rate Limiting Policy Source: https://github.com/helpingwizard/backend-repo/blob/main/API_DOCUMENTATION.md Describes the rate limiting rules implemented to prevent API abuse and ensure fair usage. It specifies different request limits for authenticated and unauthenticated users within a 15-minute window. ```APIDOC The API implements rate limiting to prevent abuse. The current limits are: - 100 requests per 15 minutes for authenticated users - 20 requests per 15 minutes for unauthenticated users ``` -------------------------------- ### Prisma Schema for User Model Source: https://github.com/helpingwizard/backend-repo/blob/main/README.md Defines the User model in Prisma, including fields for user identification, authentication, and personal details, along with relations to user tokens, RSVPs, and attendance records. ```Prisma model User { id Int @id @default(autoincrement()) name String email String @unique password String department Department year Int passoutYear Int rollNumber String @unique createdAt DateTime @default(now()) updatedAt DateTime @updatedAt tokens UserToken[] rsvps Rsvp[] attendances Attendance[] } ``` -------------------------------- ### Backend API Event Management Endpoints Source: https://github.com/helpingwizard/backend-repo/blob/main/README.md Lists the API endpoints for retrieving, creating, updating, and deleting events. Event creation, update, and deletion are restricted to admin users. ```APIDOC GET /api/events - Get all events GET /api/events/:id - Get event by ID POST /api/events - Create new event (Admin only) PUT /api/events/:id - Update event (Admin only) DELETE /api/events/:id - Delete event (Admin only) ``` -------------------------------- ### Authentication Header Format Source: https://github.com/helpingwizard/backend-repo/blob/main/API_DOCUMENTATION.md All API endpoints, except for login and registration, require a JWT token passed in the Authorization header using the Bearer scheme. ```HTTP Authorization: Bearer <your_jwt_token> ``` -------------------------------- ### Prisma Schema for Admin Model Source: https://github.com/helpingwizard/backend-repo/blob/main/README.md Defines the Admin model in Prisma, including fields for administrator identification and authentication, along with relations to admin tokens, events created, and attendance sessions managed. ```Prisma model Admin { id Int @id @default(autoincrement()) name String email String @unique password String createdAt DateTime @default(now()) updatedAt DateTime @updatedAt tokens AdminToken[] events Event[] sessions AttendanceSession[] } ``` -------------------------------- ### Create RSVP for Event API Endpoint Source: https://github.com/helpingwizard/backend-repo/blob/main/API_DOCUMENTATION.md Allows a user to create or update their RSVP status for a specific event. Requires the event ID and the desired status ('attending' or 'not_attending'). ```APIDOC POST /rsvps Request Body: { "eventId": "string", "status": "string" // "attending" or "not_attending" } Response: { "success": true, "data": { "id": "string", "userId": "string", "eventId": "string", "status": "string", "createdAt": "string", "updatedAt": "string" } } ``` -------------------------------- ### Backend API RSVP Endpoints Source: https://github.com/helpingwizard/backend-repo/blob/main/README.md Lists the API endpoints for managing RSVPs to events, including allowing users to RSVP to an event and administrators to retrieve RSVPs for a specific event. ```APIDOC POST /api/events/:id/rsvp - RSVP to an event GET /api/events/:id/rsvps - Get RSVPs for an event ``` -------------------------------- ### Prisma Schema for Attendance Model Source: https://github.com/helpingwizard/backend-repo/blob/main/README.md Defines the Attendance model in Prisma, recording the check-in time for a user within a specific attendance session, and establishing relations to both the User and AttendanceSession models. ```Prisma model Attendance { id Int @id @default(autoincrement()) checkInTime DateTime createdAt DateTime @default(now()) updatedAt DateTime @updatedAt user User @relation(fields: [userId], references: [id]) userId Int session AttendanceSession @relation(fields: [sessionId], references: [id]) sessionId Int } ``` -------------------------------- ### Mark User Attendance API Endpoint Source: https://github.com/helpingwizard/backend-repo/blob/main/API_DOCUMENTATION.md Allows a user to mark their attendance for a specific session within an event by providing a valid QR code. This endpoint records the user's check-in time and returns the attendance record details. ```APIDOC POST /events/:eventId/sessions/:sessionId/attend Request Body: { "qrCode": "string" } Response: { "success": true, "data": { "id": "string", "userId": "string", "sessionId": "string", "checkInTime": "string" } } ``` -------------------------------- ### Prisma Schema for RSVP Model Source: https://github.com/helpingwizard/backend-repo/blob/main/README.md Defines the RSVP model in Prisma, capturing the status of a user's registration for an event and establishing relations to both the User and Event models. ```Prisma model Rsvp { id Int @id @default(autoincrement()) status RsvpStatus createdAt DateTime @default(now()) updatedAt DateTime @updatedAt user User @relation(fields: [userId], references: [id]) userId Int event Event @relation(fields: [eventId], references: [id]) eventId Int } ``` -------------------------------- ### Retrieve Event RSVPs (Admin) Source: https://github.com/helpingwizard/backend-repo/blob/main/API_DOCUMENTATION.md Retrieves a list of all RSVPs for a specific event. This endpoint is restricted to admin users, providing an overview of event attendance. ```http GET /rsvps/event/:eventId ``` ```json { "success": true, "data": [ { "id": "string", "userId": "string", "eventId": "string", "status": "string", "createdAt": "string", "updatedAt": "string", "user": { "id": "string", "name": "string", "email": "string" } } ] } ``` ```APIDOC GET /rsvps/event/:eventId Description: Retrieves a list of all RSVPs for a specific event. Admin access required. Path Parameters: eventId: string - The ID of the event. Response Body: success: boolean - Indicates if the request was successful. data: array - List of event RSVPs. id: string - RSVP ID. userId: string - ID of the user who made the RSVP. eventId: string - ID of the event. status: string - RSVP status. createdAt: string - Timestamp of RSVP creation. updatedAt: string - Timestamp of last RSVP update. user: object - Details of the user who made the RSVP. id: string - User ID. name: string - User's name. email: string - User's email. ``` -------------------------------- ### Standard API Error Response Format Source: https://github.com/helpingwizard/backend-repo/blob/main/API_DOCUMENTATION.md Defines the common structure for all error responses returned by the API, including a human-readable message and a specific error code for programmatic handling. This ensures consistent error reporting across all endpoints. ```APIDOC { "success": false, "error": { "message": "string", "code": "string" } } Common error codes: - `UNAUTHORIZED`: Authentication required - `FORBIDDEN`: Insufficient permissions - `NOT_FOUND`: Resource not found - `VALIDATION_ERROR`: Invalid request data - `INTERNAL_ERROR`: Server error ``` -------------------------------- ### Retrieve User's RSVPs Source: https://github.com/helpingwizard/backend-repo/blob/main/API_DOCUMENTATION.md Retrieves a list of RSVPs for the authenticated user, including associated event details. This endpoint allows users to view their event commitments. ```http GET /rsvps/user ``` ```json { "success": true, "data": [ { "id": "string", "userId": "string", "eventId": "string", "status": "string", "createdAt": "string", "updatedAt": "string", "event": { "id": "string", "title": "string", "description": "string", "date": "string", "location": "string", "capacity": "number" } } ] } ``` ```APIDOC GET /rsvps/user Description: Retrieves a list of RSVPs for the authenticated user. Response Body: success: boolean - Indicates if the request was successful. data: array - List of user's RSVPs. id: string - RSVP ID. userId: string - ID of the user who made the RSVP. eventId: string - ID of the event. status: string - RSVP status (e.g., "attending", "not_attending"). createdAt: string - Timestamp of RSVP creation. updatedAt: string - Timestamp of last RSVP update. event: object - Details of the associated event. id: string - Event ID. title: string - Event title. description: string - Event description. date: string - Event date. location: string - Event location. capacity: number - Event capacity. ``` -------------------------------- ### JWT Token Payload Structure Source: https://github.com/helpingwizard/backend-repo/blob/main/API_DOCUMENTATION.md Describes the expected structure of the JSON Web Token (JWT) payload, which includes the user's ID and their assigned role (admin or user). ```JSON { "userId": "string", "role": "string" // "admin" or "user" } ``` -------------------------------- ### Refresh Session QR Code API Endpoint (Admin Only) Source: https://github.com/helpingwizard/backend-repo/blob/main/API_DOCUMENTATION.md Refreshes the QR code for a specific session, invalidating the previous one. This endpoint is restricted to admin users and returns the newly generated QR code along with the session ID and update timestamp. ```APIDOC POST /sessions/:sessionId/refresh-qr Response: { "success": true, "data": { "sessionId": "string", "qrCode": "string", "updatedAt": "string" } } ``` -------------------------------- ### Update Event API Endpoint (Admin Only) Source: https://github.com/helpingwizard/backend-repo/blob/main/API_DOCUMENTATION.md Allows administrators to update an existing event's details. The event is identified by its ID, and updated fields are provided in the request body. ```APIDOC PUT /events/:id Request Body: { "title": "string", "description": "string", "date": "string (ISO date)", "location": "string", "capacity": "number" } Response: { "success": true, "data": { "id": "string", "title": "string", "description": "string", "date": "string", "location": "string", "capacity": "number", "createdAt": "string", "updatedAt": "string" } } ``` -------------------------------- ### User Logout API Endpoint Source: https://github.com/helpingwizard/backend-repo/blob/main/API_DOCUMENTATION.md Logs out the current authenticated user, invalidating their session. This endpoint requires authentication. ```APIDOC POST /auth/logout Response: { "success": true, "data": { "message": "Logged out successfully" } } ``` -------------------------------- ### Update User RSVP Status Source: https://github.com/helpingwizard/backend-repo/blob/main/API_DOCUMENTATION.md Updates the status of an existing RSVP for a user. The status can be 'attending' or 'not_attending', allowing users to change their commitment. ```http PUT /rsvps/:id ``` ```json { "status": "string" // "attending" or "not_attending" } ``` ```json { "success": true, "data": { "id": "string", "userId": "string", "eventId": "string", "status": "string", "createdAt": "string", "updatedAt": "string" } } ``` ```APIDOC PUT /rsvps/:id Description: Updates the status of an existing RSVP. Path Parameters: id: string - The ID of the RSVP to update. Request Body: status: string - The new status for the RSVP. Accepted values: "attending", "not_attending". Response Body: success: boolean - Indicates if the request was successful. data: object - The updated RSVP details. id: string - RSVP ID. userId: string - ID of the user who made the RSVP. eventId: string - ID of the event. status: string - Updated RSVP status. createdAt: string - Timestamp of RSVP creation. updatedAt: string - Timestamp of last RSVP update. ``` -------------------------------- ### Delete Event API Endpoint (Admin Only) Source: https://github.com/helpingwizard/backend-repo/blob/main/API_DOCUMENTATION.md Allows administrators to delete an event from the system using its unique identifier. ```APIDOC DELETE /events/:id Response: { "success": true, "data": { "message": "Event deleted successfully" } } ``` -------------------------------- ### Delete User RSVP Source: https://github.com/helpingwizard/backend-repo/blob/main/API_DOCUMENTATION.md Deletes an existing RSVP by its ID. This action is irreversible and removes the user's commitment to an event. ```http ```