From 62fbfb97b29153046ee335f635a3280f88e5bbe9 Mon Sep 17 00:00:00 2001 From: Kfir Dayan Date: Thu, 15 Jun 2023 11:34:43 +0300 Subject: [PATCH] remove second middle ware --- src/controllers/CartController.ts | 6 +++--- src/controllers/ProductController.ts | 2 +- src/controllers/UserController.ts | 2 +- src/index.ts | 2 +- src/routes/cartRouter.ts | 6 +++--- src/routes/userRouter.ts | 2 +- src/{models => schemas}/cartModel.ts | 0 src/{models => schemas}/orderModel.ts | 0 src/{models => schemas}/productModel.ts | 0 src/{models => schemas}/userModel.ts | 2 -- src/services/sendGrid.ts | 4 ++-- 11 files changed, 12 insertions(+), 14 deletions(-) rename src/{models => schemas}/cartModel.ts (100%) rename src/{models => schemas}/orderModel.ts (100%) rename src/{models => schemas}/productModel.ts (100%) rename src/{models => schemas}/userModel.ts (95%) diff --git a/src/controllers/CartController.ts b/src/controllers/CartController.ts index 9f32590..42d6a85 100644 --- a/src/controllers/CartController.ts +++ b/src/controllers/CartController.ts @@ -1,7 +1,7 @@ import { Request, Response } from 'express'; -import { Cart, ICart } from '../models/cartModel'; -import { Product } from '../models/productModel'; -import { Order } from '../models/orderModel'; +import { Cart, ICart } from '../schemas/cartModel'; +import { Product } from '../schemas/productModel'; +import { Order } from '../schemas/orderModel'; import { sendEmailasync } from '../services/sendGrid'; import { config } from 'dotenv'; diff --git a/src/controllers/ProductController.ts b/src/controllers/ProductController.ts index 047c624..f69fdc6 100644 --- a/src/controllers/ProductController.ts +++ b/src/controllers/ProductController.ts @@ -1,5 +1,5 @@ import { Request, Response } from 'express'; -import { Product, IProduct } from '../models/productModel'; +import { Product, IProduct } from '../schemas/productModel'; export async function createProduct(req: Request, res: Response) { try { diff --git a/src/controllers/UserController.ts b/src/controllers/UserController.ts index b21ede8..047b61f 100644 --- a/src/controllers/UserController.ts +++ b/src/controllers/UserController.ts @@ -1,7 +1,7 @@ import { Request, Response } from 'express'; import bcrypt from 'bcryptjs'; import jwt from 'jsonwebtoken'; -import { User, IUser } from '../models/userModel'; +import { User, IUser } from '../schemas/userModel'; import { clearJwtCookie, setJwtCookie } from '../middlewares/checkAuth'; import validate from 'deep-email-validator'; diff --git a/src/index.ts b/src/index.ts index 56407e8..5a4aa36 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,7 +4,7 @@ import cookieParser from 'cookie-parser'; import userRouter from './routes/userRouter'; import productRouter from './routes/productRouter'; -import cartRouter from './routes/cartRoute'; +import cartRouter from './routes/cartRouter'; const env = require('dotenv').config().parsed; diff --git a/src/routes/cartRouter.ts b/src/routes/cartRouter.ts index 2349da4..5a87d44 100644 --- a/src/routes/cartRouter.ts +++ b/src/routes/cartRouter.ts @@ -1,14 +1,14 @@ import express from 'express'; import { authenticateToken } from '../middlewares/checkAuth'; import { addToCart, listCart, checkout, clearCart } from '../controllers/cartController'; -import { checkUuid } from '../middlewares/checkUuid'; +import { checkUuid } from '../middlewares/checkUuid'; const cartRouter = express.Router(); -cartRouter.post('/', [authenticateToken, checkUuid], addToCart); -cartRouter.get('/', [authenticateToken, checkUuid], listCart); +cartRouter.post('/', [authenticateToken], addToCart); +cartRouter.get('/', [authenticateToken], listCart); cartRouter.post('/checkout', authenticateToken, checkout); cartRouter.delete('/', authenticateToken, clearCart) diff --git a/src/routes/userRouter.ts b/src/routes/userRouter.ts index 51bf3b9..98f7e64 100644 --- a/src/routes/userRouter.ts +++ b/src/routes/userRouter.ts @@ -4,9 +4,9 @@ import { createUser, login, logout, getAllUsers, deleteUser } from '../controlle const userRouter = express.Router(); userRouter.post('/', createUser); +userRouter.get('/', getAllUsers); userRouter.post('/login', login); userRouter.post('/logout', logout); -userRouter.get('/all', getAllUsers); userRouter.delete('/:id', deleteUser) export default userRouter; \ No newline at end of file diff --git a/src/models/cartModel.ts b/src/schemas/cartModel.ts similarity index 100% rename from src/models/cartModel.ts rename to src/schemas/cartModel.ts diff --git a/src/models/orderModel.ts b/src/schemas/orderModel.ts similarity index 100% rename from src/models/orderModel.ts rename to src/schemas/orderModel.ts diff --git a/src/models/productModel.ts b/src/schemas/productModel.ts similarity index 100% rename from src/models/productModel.ts rename to src/schemas/productModel.ts diff --git a/src/models/userModel.ts b/src/schemas/userModel.ts similarity index 95% rename from src/models/userModel.ts rename to src/schemas/userModel.ts index f46db85..c79a538 100644 --- a/src/models/userModel.ts +++ b/src/schemas/userModel.ts @@ -1,5 +1,3 @@ -// src/models/userModel.ts - import mongoose, { Schema, Document } from 'mongoose'; interface IUser extends Document { diff --git a/src/services/sendGrid.ts b/src/services/sendGrid.ts index c805756..8d48e49 100644 --- a/src/services/sendGrid.ts +++ b/src/services/sendGrid.ts @@ -1,6 +1,6 @@ import { config } from "dotenv"; -import { Order } from "../models/orderModel"; -import { User } from "../models/userModel"; +import { Order } from "../schemas/orderModel"; +import { User } from "../schemas/userModel"; import client from '@sendgrid/mail'; config();