Skip to content

Commit

Permalink
Fix linting with air bnb style
Browse files Browse the repository at this point in the history
  • Loading branch information
MFahimKhQodeleaf committed Mar 17, 2023
1 parent 65bd459 commit 5369c7e
Show file tree
Hide file tree
Showing 6 changed files with 2,692 additions and 121 deletions.
15 changes: 15 additions & 0 deletions node-rest-shop/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"env": {
"browser": true,
"commonjs": true,
"es2021": true
},
"extends": "airbnb-base",
"overrides": [
],
"parserOptions": {
"ecmaVersion": "latest"
},
"rules": {
}
}
6 changes: 6 additions & 0 deletions node-rest-shop/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.validate": ["javascript"]
}
35 changes: 19 additions & 16 deletions node-rest-shop/api/routes/products.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
const exress = require("express");
const router = exress.Router();
const Product = require("../models/product");
const mongoose = require("mongoose");
/* eslint-disable no-shadow */
/* eslint-disable no-unused-vars */
/* eslint-disable no-restricted-syntax */
const express = require('express');

router.get("/", (req, res, next) => {
const router = express.Router();
const mongoose = require('mongoose');
const Product = require('../models/product');

router.get('/', (req, res) => {
Product.find()
.exec()
.then((docs) => {
console.log(docs);
if (docs.length >= 0) {
res.status(200).json(docs);
} else {
res.status(404).json({ error: err });
}
})
.catch((err) => {
console.log(err);
res.status(500).json({ error: err });
});
});

router.post("/", (req, res, next) => {
router.post('/', (req, res, next) => {
const product = new Product({
_id: new mongoose.Types.ObjectId(),
name: req.body.name,
Expand All @@ -31,7 +34,7 @@ router.post("/", (req, res, next) => {
.then((result) => {
console.log(result);
res.status(201).json({
message: "Product created successfully",
message: 'Product created successfully',
createProduct: result,
});
})
Expand All @@ -41,33 +44,33 @@ router.post("/", (req, res, next) => {
});
});

router.get("/:productId", (req, res, next) => {
router.get('/:productId', (req, res, next) => {
const id = req.params.productId;
Product.findById(id)
.exec()
.then((doc) => {
console.log("from db", doc);
console.log('from db', doc);
if (doc) res.status(200).json({ doc });
else res.status(404).json({ message: "Product not found" });
else res.status(404).json({ message: 'Product not found' });
})
.catch((err) => {
console.log(err);
res.status(500).json({ error: err });
});
});

router.patch("/:productId", (req, res, next) => {
router.patch('/:productId', (req, res, next) => {
const updateOps = {};
for (const ops of req.body) {
updateOps[ops.propName] = ops.value;
}
Product.update({ _id: req.params.productId }, { $set: updateOps })
.exec()
.then((res) => res.status(200).json({ message: "Product updated" }))
.catch(res.status(500).json({ error: err }));
.then((res) => res.status(200).json({ message: 'Product updated' }))
.catch((err) => res.status(500).json({ error: err }));
});

router.delete("/:productId", (req, res, next) => {
router.delete('/:productId', (req, res, next) => {
Product.remove({ _id: req.params.productId })
.exec()
.then((result) => {
Expand Down
Loading

0 comments on commit 5369c7e

Please sign in to comment.