Skip to content

Commit

Permalink
Merge pull request #89 from atlp-rwanda/fix-category
Browse files Browse the repository at this point in the history
fix: fixed category fetching allowing all user to fetch availabe catgeories
  • Loading branch information
teerenzo authored and soleil00 committed Jul 12, 2024
2 parents b54207b + 3beabba commit 6c9667e
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 66 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
/uploads
/.vscode
/dist
/demo.tsx

30 changes: 12 additions & 18 deletions src/docs/swagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,15 @@ 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";
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();

Expand All @@ -72,7 +66,7 @@ const options = {
basePath: "/",

tags: [
{ name: "Home"},
{ name: "Home" },
{ name: "Users", description: "Endpoints related to users" },
{
name: "Roles",
Expand All @@ -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: {
Expand Down Expand Up @@ -123,7 +117,7 @@ const options = {
},

"/api/v1/users/me": {
post: verifyUserAccessToken,
get: verifyUserAccessToken,
},
"/api/v1/roles": {
get: getRoles,
Expand All @@ -146,7 +140,7 @@ const options = {
delete: deleteProducts,
},
"/api/v1/products/ads": {
get: getAdProducts
get: getAdProducts,
},
"/api/v1/categories": {
get: getCategories,
Expand All @@ -169,7 +163,7 @@ const options = {
},
"/api/v1/products/{id}/wishes": {
get: getWishesByProduct,
delete: deleteWish
delete: deleteWish,
},
"/api/v1/products/search": {
get: searchProduct,
Expand All @@ -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,
Expand All @@ -215,7 +209,7 @@ const options = {
Category: categorySchema,
Wish: wishSchema,
Review: reviewSchema,
PrivateChat: PrivateChatSchema
PrivateChat: PrivateChatSchema,
},
securitySchemes: {
bearerAuth: {
Expand Down
6 changes: 1 addition & 5 deletions src/middlewares/verifyToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
23 changes: 8 additions & 15 deletions src/routes/categoriesRoutes.ts
Original file line number Diff line number Diff line change
@@ -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;
export default categoriesRouter;
73 changes: 45 additions & 28 deletions src/routes/userRoutes.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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);

Expand Down

0 comments on commit 6c9667e

Please sign in to comment.