sainRaghuveer / VarthakTechnologies-assignment

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.

Home Page:https://varthak-backend.onrender.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Book Management App

About


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.

Installation

npm install

Start the Backend server

npm run start

npm run server

node index.ts

nodemon start

nodemon index.ts

Note : You can use any of them


MVC Structure

├── 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 put PORT , 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.

Schema Design


User Schema

{
    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
}

Book Schema

{
    title: { type: String, required: true },
    author: { type: String, required: true },
    createdBy: { type: Schema.Types.ObjectId, ref: 'User', required: true }
  }, {
    timestamps: true,
    versionKey: false
}

Endpoints

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

Backend deployed link

Render

About

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.

https://varthak-backend.onrender.com/


Languages

Language:TypeScript 100.0%