From 3beabba2e387e1312aedc2c315ca8cae155da7a6 Mon Sep 17 00:00:00 2001 From: soleil00 Date: Sun, 7 Jul 2024 14:22:39 +0200 Subject: [PATCH] fixed category fetch allowong user to fetch availabe categories --- src/docs/swagger.ts | 30 ++++++-------- src/middlewares/verifyToken.ts | 6 +-- src/routes/categoriesRoutes.ts | 23 ++++------- src/routes/userRoutes.ts | 73 +++++++++++++++++++++------------- 4 files changed, 66 insertions(+), 66 deletions(-) diff --git a/src/docs/swagger.ts b/src/docs/swagger.ts index a6d2b27..37024eb 100644 --- a/src/docs/swagger.ts +++ b/src/docs/swagger.ts @@ -32,13 +32,7 @@ import { changeProductAvailability, } from "./products"; import { getCategories, addCategories, getSingleCategory, updateCategories, deleteCategories, categorySchema } from "./categories"; - import { - RoleSchema, - getRoles, - createRole, - updateRole, - deleteRole - } from "./roledoc"; +import { RoleSchema, getRoles, createRole, updateRole, deleteRole } from "./roledoc"; import { AddToWishes, deleteWish, getWishes, getWishesByProduct, wishSchema } from "./wishes"; import { addItemToCartDoc, clearAllProductFromCartDoc, removeProductFromCartDoc, updateProductQuantityDoc, viewCartDoc } from "./cart"; import { getAllNotifications, readNotification } from "./notifications"; @@ -46,7 +40,7 @@ import { homepage } from "./home"; import { payment } from "./payments"; import { createReviewProduct, deleteReview, getReviewProduct, reviewSchema, updateReviewProduct } from "./reviews"; import { getAdProducts } from "./products"; -import {PrivateChatSchema, getAllUserPrivateChats, getUserToUserPrivateMessages, createPrivateChat } from "./privateChatDoc" +import { PrivateChatSchema, getAllUserPrivateChats, getUserToUserPrivateMessages, createPrivateChat } from "./privateChatDoc"; const docRouter = express.Router(); @@ -72,7 +66,7 @@ const options = { basePath: "/", tags: [ - { name: "Home"}, + { name: "Home" }, { name: "Users", description: "Endpoints related to users" }, { name: "Roles", @@ -81,9 +75,9 @@ const options = { { name: "Products", description: "Endpoints related to products" }, { name: "Categories", description: "Endpoints related categories" }, { name: "Wishes", description: "Endpoints related to Wishes" }, - { name: "Carts", description: "Endpoints related to Cart"}, + { name: "Carts", description: "Endpoints related to Cart" }, { name: "Payments", description: "Endpoints related to payments" }, - {name: "PrivateChat", description: "Endpoints related to Private Chat"}, + { name: "PrivateChat", description: "Endpoints related to Private Chat" }, ], paths: { @@ -123,7 +117,7 @@ const options = { }, "/api/v1/users/me": { - post: verifyUserAccessToken, + get: verifyUserAccessToken, }, "/api/v1/roles": { get: getRoles, @@ -146,7 +140,7 @@ const options = { delete: deleteProducts, }, "/api/v1/products/ads": { - get: getAdProducts + get: getAdProducts, }, "/api/v1/categories": { get: getCategories, @@ -169,7 +163,7 @@ const options = { }, "/api/v1/products/{id}/wishes": { get: getWishesByProduct, - delete: deleteWish + delete: deleteWish, }, "/api/v1/products/search": { get: searchProduct, @@ -188,13 +182,13 @@ const options = { get: readNotification, }, "/api/v1/payment/checkout": { - post: payment + post: payment, }, - "/api/v1/products/{pid}/reviews": { + "/api/v1/products/{pid}/reviews": { get: getReviewProduct, post: createReviewProduct, patch: updateReviewProduct, - delete: deleteReview + delete: deleteReview, }, "/api/v1/chats/private": { get: getAllUserPrivateChats, @@ -215,7 +209,7 @@ const options = { Category: categorySchema, Wish: wishSchema, Review: reviewSchema, - PrivateChat: PrivateChatSchema + PrivateChat: PrivateChatSchema, }, securitySchemes: { bearerAuth: { diff --git a/src/middlewares/verifyToken.ts b/src/middlewares/verifyToken.ts index 86271c9..043d5af 100644 --- a/src/middlewares/verifyToken.ts +++ b/src/middlewares/verifyToken.ts @@ -34,11 +34,7 @@ export const verifyToken = async (req: Request, res: Response) => { message: "Token has expired. Please login again.", }); } - return res.status(200).json({ - message: "You're Logged In Successfully", - username: user.username, - user, - }); + return res.status(200).json(user); } catch (error: any) { return res.status(401).json({ status: "failed", diff --git a/src/routes/categoriesRoutes.ts b/src/routes/categoriesRoutes.ts index 6007672..45e7f54 100644 --- a/src/routes/categoriesRoutes.ts +++ b/src/routes/categoriesRoutes.ts @@ -1,23 +1,16 @@ import { Router } from "express"; import { upload } from "../utils/uploadImages"; -import { - fetchCategories, - addCategories, - fetchSingleCategory, - categoriesUpdate, - removeCategories - } from "../controllers/categoriesControllers"; - import { validateSchema } from "../middlewares/validator"; +import { fetchCategories, addCategories, fetchSingleCategory, categoriesUpdate, removeCategories } from "../controllers/categoriesControllers"; +import { validateSchema } from "../middlewares/validator"; import { categoriesDataSchema } from "../schemas/categorySchema"; import { isAseller } from "../middlewares/sellerAuth"; import { isLoggedIn } from "../middlewares/isLoggedIn"; import { isPasswordOutOfDate } from "../middlewares/isPasswordOutOfDate"; const categoriesRouter = Router(); -categoriesRouter.get("/",isLoggedIn,isPasswordOutOfDate,isAseller,fetchCategories); -categoriesRouter.get("/:id",isLoggedIn,isPasswordOutOfDate,isAseller,fetchSingleCategory); -categoriesRouter.post("/",isLoggedIn,isPasswordOutOfDate,isAseller,upload.single('image'),validateSchema(categoriesDataSchema) -,addCategories); -categoriesRouter.patch("/:id",isAseller,isPasswordOutOfDate,upload.single('image'),categoriesUpdate); -categoriesRouter.delete("/:id",isLoggedIn,isPasswordOutOfDate,isAseller,removeCategories); +categoriesRouter.get("/", fetchCategories); +categoriesRouter.get("/:id", isLoggedIn, isPasswordOutOfDate, isAseller, fetchSingleCategory); +categoriesRouter.post("/", isLoggedIn, isPasswordOutOfDate, isAseller, upload.single("image"), validateSchema(categoriesDataSchema), addCategories); +categoriesRouter.patch("/:id", isAseller, isPasswordOutOfDate, upload.single("image"), categoriesUpdate); +categoriesRouter.delete("/:id", isLoggedIn, isPasswordOutOfDate, isAseller, removeCategories); -export default categoriesRouter; \ No newline at end of file +export default categoriesRouter; diff --git a/src/routes/userRoutes.ts b/src/routes/userRoutes.ts index 6c89cfe..743892d 100644 --- a/src/routes/userRoutes.ts +++ b/src/routes/userRoutes.ts @@ -1,5 +1,24 @@ import { Router } from "express"; -import { fetchAllUsers, createUserController, userLogin, updatePassword, tokenVerification, handleSuccess, handleFailure,updateProfileController, getProfileController, otpVerification,updateUserRole, changeUserAccountStatus, logout, sendResetLinkEmail, resetPasswordController, verifyUserEmailController, verifyUserController, fetchAllsellers } from "../controllers/userControllers"; +import { + fetchAllUsers, + createUserController, + userLogin, + updatePassword, + tokenVerification, + handleSuccess, + handleFailure, + updateProfileController, + getProfileController, + otpVerification, + updateUserRole, + changeUserAccountStatus, + logout, + sendResetLinkEmail, + resetPasswordController, + verifyUserEmailController, + verifyUserController, + fetchAllsellers, +} from "../controllers/userControllers"; import { emailValidation, validateSchema } from "../middlewares/validator"; import { isLoggedIn } from "../middlewares/isLoggedIn"; import { passwordUpdateSchema } from "../schemas/passwordUpdate"; @@ -19,41 +38,39 @@ import { isPasswordOutOfDate } from "../middlewares/isPasswordOutOfDate"; import { isVerified } from "../middlewares/isVerified"; const userRoutes = Router(); -userRoutes.get("/",isLoggedIn,isAdmin, fetchAllUsers); -userRoutes.put("/passwordupdate", isLoggedIn, validateSchema(passwordUpdateSchema), updatePassword) -userRoutes.post("/login", emailValidation,validateSchema(logInSchema),isDisabled,isVerified,userLogin); +userRoutes.get("/", isLoggedIn, isAdmin, fetchAllUsers); +userRoutes.put("/passwordupdate", isLoggedIn, validateSchema(passwordUpdateSchema), updatePassword); +userRoutes.post("/login", emailValidation, validateSchema(logInSchema), isDisabled, isVerified, userLogin); userRoutes.post("/register", emailValidation, validateSchema(signUpSchema), createUserController); userRoutes.put("/passwordupdate", isLoggedIn, validateSchema(passwordUpdateSchema), updatePassword); -userRoutes.get("/sellers", fetchAllsellers) -userRoutes.put("/passwordupdate", isLoggedIn,validateSchema(passwordUpdateSchema), updatePassword) -userRoutes.post("/login", emailValidation,validateSchema(logInSchema),isDisabled,userLogin); -userRoutes.post("/register", emailValidation,validateSchema(signUpSchema), createUserController); -userRoutes.get("/2fa-verify/:token",tokenVerification); -userRoutes.post("/2fa-verify",otpVerification); -userRoutes.get('/profile', - isLoggedIn, isPasswordOutOfDate, - getProfileController -); -userRoutes.post('/logout', isLoggedIn, logout); -userRoutes.patch('/profile', - isLoggedIn,isPasswordOutOfDate, - upload.single('profileImage'), - validateSchema(profileSchemas), - isUploadedFileImage, - updateProfileController +userRoutes.get("/sellers", fetchAllsellers); +userRoutes.put("/passwordupdate", isLoggedIn, validateSchema(passwordUpdateSchema), updatePassword); +userRoutes.post("/login", emailValidation, validateSchema(logInSchema), isDisabled, userLogin); +userRoutes.post("/register", emailValidation, validateSchema(signUpSchema), createUserController); +userRoutes.get("/2fa-verify/:token", tokenVerification); +userRoutes.post("/2fa-verify", otpVerification); +userRoutes.get("/profile", isLoggedIn, isPasswordOutOfDate, getProfileController); +userRoutes.post("/logout", isLoggedIn, logout); +userRoutes.patch( + "/profile", + isLoggedIn, + isPasswordOutOfDate, + upload.single("profileImage"), + validateSchema(profileSchemas), + isUploadedFileImage, + updateProfileController, ); -userRoutes.patch("/:id/role",isLoggedIn,isPasswordOutOfDate, isAdmin, validateSchema(roleUpdateSchema), userExist, roleExist, updateUserRole) -userRoutes.patch('/:userId/status',isLoggedIn,isPasswordOutOfDate, isAdmin, changeUserAccountStatus); +userRoutes.patch("/:id/role", isLoggedIn, isPasswordOutOfDate, isAdmin, validateSchema(roleUpdateSchema), userExist, roleExist, updateUserRole); +userRoutes.patch("/:userId/status", isLoggedIn, isPasswordOutOfDate, isAdmin, changeUserAccountStatus); userRoutes.get("/auth/google", authenticateUser); userRoutes.get("/auth/google/callback", callbackFn); userRoutes.get("/auth/google/success", handleSuccess); userRoutes.get("/auth/google/failure", handleFailure); -userRoutes.post('/password-reset-link', sendResetLinkEmail); -userRoutes.patch('/reset-password', resetPasswordController); -userRoutes.post('/verify-user-email', verifyUserEmailController); -userRoutes.get('/verify-user', verifyUserController); - +userRoutes.post("/password-reset-link", sendResetLinkEmail); +userRoutes.patch("/reset-password", resetPasswordController); +userRoutes.post("/verify-user-email", verifyUserEmailController); +userRoutes.get("/verify-user", verifyUserController); userRoutes.get("/me", verifyToken);