-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.js
151 lines (115 loc) · 3.82 KB
/
routes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
const cookieParser = require("cookie-parser");
const express = require("express");
const cors = require("cors");
const router = express.Router();
const auth = require("./middlewares/auth");
const {
authenticate,
logOutUser,
getProfile,
getUsers,
suggestUser,
getSingleUser,
getFollowerData,
getFollowingData,
getUserPosts,
getSinglePost,
getUserFeedPosts,
getPostLikers,
getComments,
getReplies,
register,
login,
postSomething,
reply,
postComment,
updateAvatar,
updateProfileInfo,
followUser,
unFollowUser,
updatePost,
likePost,
unLikePost,
deletePost,
deleteSinglePost,
deleteReply,
getAllUsersPost,
} = require("./controller");
router.use(express.json({ limit: "20mb" }));
router.use(express.urlencoded({ extended: true, limit: "20mb" }));
router.use(cookieParser());
router.use(cors());
// * All the get routes starts from here
// router.get("/", (req, res) => res.send("Server is up and running"));
// this middleware route is giving me all the data of the user
// in the front-end side
// for more information, check out auth.js
router.get("/auth", auth, authenticate);
// for logging out the user
router.get("/logout", auth, logOutUser);
// for individual users profile page data
router.get("/apiProfile/:id", getProfile);
// for getting all the user data
router.get("/getUsers", auth, getUsers);
// for suggesting some users
router.get("/suggestUser", auth, suggestUser);
// for getting a single user data in the user's page after search
router.get("/getUsers/:id", auth, getSingleUser);
// for getting all the follower details
router.get("/getAllFollowerData/:ids", auth, getFollowerData);
// for getting all the following details
router.get("/getAllFollowingData/:ids", auth, getFollowingData);
// for getting a certain amount of post
router.get("/posts/:id", auth, getUserPosts);
// for getting all the posts of an user
router.get("/getUsersPost/:id", auth, getAllUsersPost);
// for getting the data of a single post
// according to the id
router.get("/singlePost/:id", auth, getSinglePost);
// for showing the posts in the home page according to the
// following list
router.get("/followingPost/:ids", auth, getUserFeedPosts);
// for getting all the likers data
// who has liked the post
router.get("/getLikersData/:ids", auth, getPostLikers);
// for getting all the comments for a specific post
// according to the id
router.get("/allComments/:postId", auth, getComments);
// for getting all the particular replies of a comment
router.get("/getReplies/:id", auth, getReplies);
// * all the post routes starts from here
// for registering a user's account
router.post("/register", register);
// for logging in/authenticating the user
router.post("/login", login);
// for posting something in the news feed
router.post("/post", auth, postSomething);
// for replying to a comment
router.post("/reply", auth, reply);
// for posting a comment
router.post("/postComment", auth, postComment);
// * all the put requests starts from here
// for updating the user avatar
router.put("/updateAvatar", auth, updateAvatar);
// for updating the profile information
router.put("/updateProfileInfo", auth, updateProfileInfo);
// for following a user
router.put("/followUser", auth, followUser);
// for unFollowing a user
router.put("/unfollowUser", auth, unFollowUser);
// for updating a post
router.put("/updatePost", auth, updatePost);
// for liking a post
router.put("/like", auth, likePost);
// for unLiking a post
router.put("/unlike", auth, unLikePost);
// * all the delete routes starts from here
// for deleting a post
// and his comments (kids 🤣)
router.delete("/deletePost/:id", auth, deletePost);
// for deleting a comment
// ! spelling wrong
router.delete("/deleteCommet/:id", auth, deleteSinglePost);
// for deleting a reply
router.delete("/deleteReply/:id", auth, deleteReply);
module.exports = router;