#NODEJS EXPRESS MONGODB
The project aim's to develop un API with node JS, Express and mongodb, the Api will manage the system of trade commercial, with the selling product and a system of cart where where the user can add and remove product on the cart.
####We have two Collection Mongo Db
######Product
schema:
{
"name": String,
"price": Number,
"category": String,
"description": String,
"quantity": Number
}
link with collection we fund routes:
get all products
{ route: { path: 'products/', method: 'get' } },
> > GET a product by id
{ route: { path: 'product/:id', method: 'get' } },
{ params: {"id": String} > > CREATE a product
{ route: { path: '/product', method: 'post' } },
{ params: {"name": String, "price": Number, "category": String, "description": String, "quantity": Number} > > UPDATE a product by id
{ route: { path: '/product:id', method: 'patch' } },
{ params: {"name?": String, "price?": Number, "category?": String, "description?": String, "quantity?": Number} > > DELETE a product by id
{ route: { path: '/product:id', method: 'delete' } },
{ params: {"id": String}
______________________________________
######Command
schema:
{
"date": Date,
"createdAt": Date,
"updatedAt": Date,
"articles": [],
"min_price": Number,
"isCompleted": Boolean,
}
link with collection we fund routes:
FIND a command by date
{ route: { path: 'command/find/date/:date', method: 'get' } }, { params: {"date": String }
> > FIND a command by date and price
{ route: { path: 'command/find/:date&:price', method: 'get' } }, { params: {"date": String, "price": String }
> > FIND a command by sort by or(date, articles, price)
{ route: { path: 'product/sort*?', method: 'get' } },
{ params: {date: String, articles: String, price} > > UPDATE a command by id
{ route: { path: 'command/:id', method: 'patch' } },
{ params: {"date?": Date, "articles?": [], "min_price?": number, "isCompleted": boolean} > > UPDATE add a product in the command by id
{ route: { path: '/command/add/:id&:productId', method: 'patch' } },
{ params: {"id": String} > > UPDATE delete a product in the command by id
{ route: { path: '/command/add/:id&:productId', method: 'patch' } },
{ params: {"id": String, "productId": String} > > UPDATE delete a product in the command by id
{ route: { path: '/command/buy/:id', method: 'patch' } },
{ params: {"id": String}
$ npm install
###Add collection
- Folder ${collection_name}
- create file ${collection_name}.controller.ts / ${collection_name}.interface.ts / ${collection_name}.service.ts / ${collection_name}.service.ts
- Create folder Schema/dto/model
- inside model create file ${collection_name}.model.ts / ${collection_name}.schema.ts
- add your ${controller_name} build/server.ts
create file "config.env" inside of config folder and add this missing information :
PORT =
MONGO_URI =
JWT_SECRET =
# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod
$ docker-compose up
- Author - Mackendy-Pierre Anselin
- linkedin - https://www.linkedin.com/in/mp-anselin-827027167/