8000 GitHub - zKevz/voting-system-backend
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

zKevz/voting-system-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Voting System Backend

A RESTful API backend for a voting system built with Express.js and MongoDB.

Prerequisites

  • Node.js (v14 or higher)
  • MongoDB (running locally on port 27017)

Installation

  1. Clone the repository:
git clone https://github.com/yourusername/voting-system.git
cd voting-system/voting-system-backend
  1. Install dependencies:
npm install
  1. Set up environment variables: Create a .env file in the root directory and add the following variables:
SECRET_KEY=your_jwt_secret_key_here

Running the Application

  1. Make sure MongoDB is running locally
  2. Start the application:
node .

The server will start on port 3000 by default.

API Endpoints

Authentication

  • POST /api/v1/auth/register - Register a new user
  • POST /api/v1/auth/login - Login with username and password

Users

  • GET /api/v1/users/me - Get current user info
  • GET /api/v1/users - Get all users (admin only)
  • DELETE /api/v1/users?id=userId - Delete a user (admin only)

Voting

  • GET /api/v1/votings - Get all voting options (admin only)
  • POST /api/v1/votings - Create a new voting option
  • GET /api/v1/votings/vote?id=votingId - Vote for an option
  • DELETE /api/v1/votings?id=votingId - Delete a voting option (admin only)

Running Tests

The application uses Jest and Supertest for testing.

  1. Make sure MongoDB is running locally
  2. Run the tests:
npm test

This will start Jest in watch mode, which will automatically rerun tests when files change.

Project Structure

  • src/ - Source code

    • controllers/ - Route handlers
    • middlewares/ - Express middlewares
    • models/ - Mongoose models
    • response/ - Response formatting
    • services/ - Business logic
    • app.js - Express application setup
    • index.js - Application entry point
  • tests/ - Test files

Notes

  • The admin user is automatically created when registering with the username "admin"
  • Users can only vote once
  • Deleted users and voting options are soft-deleted (marked as deleted in the database)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0