Table of Contents
- Clone the repository by running the following command in your terminal:
git clone git@github.com:aayushchugh/myccet-server.git
- Install the dependencies by running the following command in your terminal:
yarn install
- Create a
.env
file in the root directory of the project and add the following environment variables:
PORT=<your-port>
DB_URI=<your-mongo-uri>
NODE_ENV="development"
ACCESS_TOKEN_PRIVATE_KEY=<your-access-token-private-key>
ACCESS_TOKEN_PUBLIC_KEY=<your-access-token-public-key>
REFRESH_TOKEN_PRIVATE_KEY=<your-refresh-token-private-key>
REFRESH_TOKEN_PUBLIC_KEY=<your-refresh-token-public-key>
- Run the project by running the following command in your terminal:
yarn start
The server will start running on the port you specified in the .env
file.
All the API endpoints are documented using postman.
To create super admin run the following command in your terminal:
yarn build
node build/bin/index.js create-admin -f <first-name> -e <email> -p <phone number> -s <password>
⚠️ make sure to run the command in the root directory of the project and replace the values in <> with the actual values.
graph LR
A[Request] --> B(Route)
B --> C{Middleware}
C -->|yes| D[Middlware]
C -->|no| E[Controller]
D ---> E
E ---> F(Services)
F ---> G(Database)
G ---> F
F ---> E
E ---> H[Response]
├── src
│ ├── app.ts
│ ├── controllers -> contains all the controllers
│ │ └── auth.controller.ts
│ ├── middlewares -> contains all the middlewares
│ │ └── deserializeUser.middleware.ts
│ ├── routes -> contains all the routes
│ │ └── auth.routes.ts
│ ├── schemas -> contains all the schemas, schemas are created using zod, schemas are used to validate the request body
│ │ └── auth.schema.ts
│ ├── models -> contains database schemas
│ │ └── user.model.ts
│ ├── services -> contains all queries related to database
│ │ └── user.service.ts
│ └── utils -> contains all the utility functions
│ └── logger.util.ts
- Ensure that you have the latest version of the
main
branch by running the following command in your terminal:
git pull origin main
- Create a new branch by running the following command in your terminal:
git checkout -b <branch-name>
-
Make sure that model is created for the new functionality in the
models
folder.Eg: If you are creating a route to register a user, then make sure that the
user.model.ts
file is created in themodels
folder. and all the required fields are added to the model. -
Create a new schema for the new functionality in the
schemas
folder.Eg: If you are creating a route to register a user, then make sure that the
user.schema.ts
file is created in theschemas
folder. and all the required fields are added to the schema. -
Create a new controller for the new functionality in the
controllers
folder.Eg: If you are creating a route to register a user, then make sure that the
auth.controller.ts
file is created in thecontrollers
folder. and all the required functions are added to the controller. -
Create a new route for the new functionality in the
routes
folder.Eg: If you are creating a route to register a user, then make sure that the
auth.routes.ts
file is created in theroutes
folder. and all the required routes are added to the routes file. -
Register the new routes in the
app.ts
file. -
Write documentation for the new routes in the
swagger.json
file. -
Commit your changes by running the following command in your terminal:
git add .
git commit -m "<commit-message>"
- Push your changes by running the following command in your terminal:
git push origin <branch-name>
- Create a pull request to merge your changes to the
main
branch. - Wait for the pull request to be reviewed and merged.
All the API endpoints return the response in the following format:
- Successful Response
{
"success": true,
"statusCode": 201,
"data": {
"message": "UserModel registered successfully"
}
}
- Successful Response with multiple records
{
"success": true,
"statusCode": 200,
"data": {
"message": "Users fetched successfully",
"records": [
{
"name": "John Doe",
"email": "john@gmail.com"
},
{
"name": "Harry Potter",
"email": "harry@gmail.com"
}
],
"count": 2,
"limit": 10,
"page": 1
}
}
- Successful Response with single record
{
"success": true,
"statusCode": 200,
"data": {
"message": "UserModel fetched successfully",
"record": {
"name": "John Doe",
"email": "john@gmail.com"
}
}
}
- Error Response
{
"success": false,
"statusCode": 409,
"error": {
"detail": "User already exists",
"code": "USER_ALREADY_EXISTS"
}
}
⚠️ Make sure that the response is returned in the above format only and contains proper status codes.