Skip to content

victorvhs017/xm-backend

Repository files navigation

Lint and Prettier Check codecov Quality Gate Status

Overview

This project is a backend service built with Next.js, Prisma, and TypeScript. It provides a set of API endpoints for managing feedback and contact information for an Enterprise-Ready XM Backend.

Key Directories and Files

  • .env: Environment variables configuration.
  • .next: Next.js build output.
  • prisma: Contains Prisma schema and migration files.
  • src: Source code for the application.
    • app/: Contains API route handlers.
    • utils/: Utility functions.
    • client.ts: Prisma client instance.
  • next.config.ts: Next.js configuration file.
  • tsconfig.json: TypeScript configuration file.
  • package.json: Project dependencies and scripts.

Environment Variables

The .env file contains the following environment variables:

DATABASE_URL="your database connection string"
NEXTAUTH_SECRET="your next-auth secret"

Prisma uses this variable to connect to the PostgreSQL database.

API Endpoints

Feedback Endpoints

  • GET /api/feedback: Retrieve all feedback.
  • POST /api/feedback: Create new feedback.
  • GET /api/feedback/[id]: Retrieve feedback by ID.
  • PUT /api/feedback/[id]: Update feedback by ID.
  • DELETE /api/feedback/[id]: Delete feedback by ID.

Contact Endpoints

  • GET /api/contact: Retrieve all contacts.
  • POST /api/contact: Create new contact.
  • GET /api/contact/[id]: Retrieve contact by ID.
  • PUT /api/contact/[id]: Update contact by ID.
  • DELETE /api/contact/[id]: Delete contact by ID.

Authentication

This project uses NextAuth.js for authentication. The authentication strategy is based on JWT (JSON Web Tokens) and credentials provider.

Register a New User

To register a new user, send a POST request to /api/register with the following JSON payload:

{
  "email": "user@example.com",
  "password": "yourpassword",
  "name": "Your Name"
}

Login

To log in, send a POST request to /api/login with the following JSON payload:

{
  "email": "user@example.com",
  "password": "yourpassword"
}

The response will contain a JWT token that you can use to authenticate your requests.

Authenticating Requests

To authenticate your requests, include the JWT token in the Authorization header as follows:

Authorization: Bearer <your-jwt-token>

Running the Project

  1. Install dependencies:
npm install
  1. Set up the database:
npx prisma migrate dev
  1. Start the development server:
npm run dev

Testing the Project

To run the tests, use the following commands:

  1. Run all tests:
npm run test
  1. Run tests in watch mode:
npm run test:watch
  1. Generate a test coverage report:
npm run test:coverage

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

Enterprise-Ready open-source XM backend

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published