This is the server side github of https://github.com/fms-faisal/skyview-apartments-client
This Node.js Express application provides a backend API for managing apartments, reservations, users, announcements, and payments for an apartment complex named "Skyview Apartments."
- Express.js: Web framework for building APIs
- MongoDB: NoSQL database for data storage
- JWT (JSON Web Token): Authentication mechanism
- Stripe: Payment processing platform
-
Clone this repository.
git clone https://github.com/fms-faisal/skyview-apartments-server.git -
Navigate to the project directory.
cd skyview-apartments-server -
Install dependencies:
npm install -
Set Up Environment Variables Create a
.envfile in the project root directory and set the following environment variables:DB_USER: Your MongoDB usernameDB_PASS: Your MongoDB passwordACCESS_TOKEN_SECRET: A secret key used for generating JWT tokensSTRIPE_SECRET_KEY: Your Stripe secret key
-
Start the server:
node index.js -
The server will listen on port 5000 by default (configurable via
PORTenvironment variable).
- GET
/users(Public): Retrieves all users. - GET
/users/admin/:email(Protected): Checks if a user is an admin. Requires a valid JWT token in the authorization header. - GET
/users/member/:email(Protected): Checks if a user is a member. Requires a valid JWT token in the authorization header. - POST
/users(Public): Creates a new user. - DELETE
/users/:id(Protected, Admin Only): Deletes a user. Requires a valid JWT token and admin privileges in the authorization header. - PATCH
/users/admin/:id(Protected, Admin Only): Updates a user's role to "admin." Requires a valid JWT token and admin privileges in the authorization header.
- GET
/apartments(Public): Retrieves all apartments.
- POST
/reservation: Creates a new reservation. - GET
/reservation/agreement: Retrieves pending reservations. - DELETE
/reservation/:id: Deletes a reservation.
- POST
/jwt(Public): Generates a JWT token for a user.
- GET
/announcement: Retrieves all announcements. - POST
/announcement: Creates a new announcement.
- POST
/create-payment-intent: Creates a Stripe payment intent for a specific amount. - POST
/payments: Records a payment and deletes associated reservations. - GET
/payments/:email: Retrieves payments for a specific user (based on email).