This is a backend application that manages books and their creators. It provides APIs for creating books, viewing books, and filtering books based on creation time. The application is built using Node.js and TypeScript with the Express framework and MongoDB for data storage.
npm install
npm run start
npm run server
node index.ts
nodemon start
nodemon index.ts
Note : You can use any of them
├── logs
| └── api.log
├── src
├── config
| └── db.ts
├── models
| └── book.model.ts
| └── user.model.ts
├── routes
| └── book.model.ts
| └── auth.model.ts
├── middleware
| └── authentication.middleware.ts
├──controllers
| └── auth.controller.ts
| └── book.controller.ts
└── index.ts
Note:
- Before doing anything first create
.env
file and putPORT
,MONGO_URL
. PORT
is for listening the server.MONGO_URL
is for running database and store your data in database so put your mongo link.
{
name: { type: String, required: true },
email: { type: String, required: true },
password: { type: String, required: true },
mobileNumber: { type: Number, required: true, min: 10 },
role: { type: String, enum: ["CREATOR", "VIEWER", "VIEW_ALL"], required: true }
}, {
timestamps: true,
versionKey: false
}
{
name: { type: String, required: true },
email: { type: String, required: true },
password: { type: String, required: true },
mobileNumber: { type: Number, required: true, min: 10 },
role: { type: String, enum: ["CREATOR", "VIEWER", "VIEW_ALL"], required: true }
}, {
timestamps: true,
versionKey: false
}
{
title: { type: String, required: true },
author: { type: String, required: true },
createdBy: { type: Schema.Types.ObjectId, ref: 'User', required: true }
}, {
timestamps: true,
versionKey: false
}
{
title: { type: String, required: true },
author: { type: String, required: true },
createdBy: { type: Schema.Types.ObjectId, ref: 'User', required: true }
}, {
timestamps: true,
versionKey: false
}
METHOD | ENDPOINT | DESCRIPTION | STATUS CODE |
---|---|---|---|
POST | /signup | This endpoint should allow users to register. Hash the password on store. | 201 |
POST | /login | This endpoint should allow users to login. Return JWT token on login. | 201 |
POST | /books | This endpoint is used to create new book with role of CREATOR | 200 |
GET | /books | This endpoint is used view book with role of VIEWER | 200 |
GET | /books/all | This endpoint is used view book with role of VIEW_ALL | 200 |
GET | /books/filter?`old/new=1` | This endpoint is for view books with filtering according to time | 200 |