Skip to content

Commit

Permalink
set up vercel
Browse files Browse the repository at this point in the history
  • Loading branch information
joec05 committed Dec 11, 2023
1 parent 5004215 commit e3d11da
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 13 deletions.
27 changes: 21 additions & 6 deletions dist/controllers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -979,8 +979,6 @@ usersRoutes.get('/fetchFeed', (req, res) => __awaiter(void 0, void 0, void 0, fu
const fetchFollowingData = yield postsClient.query(fetchFollowingDataQuery, [
userID, 0, maxFetchLimit, username, IP, PORT, password
]);
for (var i = 0; i < 50; i++) {
}
const feedPosts = fetchFollowingData.rows.map((e) => e.post_data);
const totalPostsLength = Math.min(maxFetchLimit, feedPosts.length);
var modifiedFeedPosts = [...feedPosts];
Expand Down Expand Up @@ -1985,7 +1983,7 @@ usersRoutes.get('/fetchSearchedCommentsPagination', (req, res) => __awaiter(void
usersRoutes.get('/fetchSearchedUsers', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
const { searchedText, currentID, currentLength, paginationLimit, maxFetchLimit } = req.body;
try {
const fetchSearchedUsersDataQuery = `SELECT user_id FROM basic_data.user_profile WHERE lower(name) LIKE '%lower(${searchedText})%' OR username LIKE '%lower(${searchedText})%'`;
const fetchSearchedUsersDataQuery = `SELECT user_id FROM basic_data.user_profile WHERE name LIKE '%${searchedText}%' OR username LIKE '%${searchedText}%'`;
const fetchSearchedUsersData = yield profilesClient.query(fetchSearchedUsersDataQuery, []);
var searchedUsersData = fetchSearchedUsersData.rows.map((e) => e.user_id);
const totalUsersLength = searchedUsersData.length;
Expand Down Expand Up @@ -2267,15 +2265,32 @@ usersRoutes.get('/fetchSearchedTagUsers', (req, res) => __awaiter(void 0, void 0
return res.json({ message: 'Internal Server Error' });
}
}));
usersRoutes.get('/fetchTopHashtags', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
const { paginationLimit } = req.body;
usersRoutes.get('/fetchTopData', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
const { currentID, paginationLimit } = req.body;
try {
const fetchTopPostsQuery = `SELECT * FROM public."fetch_most_popular_posts"($1, $2, $3, $4, $5, $6)`;
const fetchTopPosts = yield postsClient.query(fetchTopPostsQuery, [
currentID, paginationLimit,
username, IP, PORT, password
]);
const postsList = fetchTopPosts.rows.map((e) => e.post_data);
var getCompletePostsData = yield getPostsListFilteredData(postsList, currentID);
const completePostsList = getCompletePostsData.completeDataList;
const fetchTopUsersQuery = `SELECT * FROM public."fetch_most_popular_users"($1, $2)`;
const fetchTopUsers = yield profilesClient.query(fetchTopUsersQuery, [currentID, paginationLimit]);
const usersID = fetchTopUsers.rows.map((e) => e.user_id);
var getCompleteUsersData = yield getUsersListFilteredData(usersID, currentID);
const usersProfileData = [...new Set([...getCompleteUsersData.usersProfileData, ...getCompletePostsData.usersProfileData])];
const usersSocialsData = [...new Set([...getCompleteUsersData.usersSocialsData, ...getCompletePostsData.usersSocialsData])];
const fetchHashtagsDataQuery = `SELECT * FROM hashtags.hashtags_list ORDER BY hashtag_count DESC OFFSET $1 LIMIT $2`;
const fetchHashtagsData = yield keywordsClient.query(fetchHashtagsDataQuery, [0, paginationLimit]);
const hashtagsData = fetchHashtagsData.rows;
res.json({
'message': "Successfully fetched hashtags data",
'hashtagsData': hashtagsData
'hashtagsData': hashtagsData,
'usersProfileData': usersProfileData,
'usersSocialsData': usersSocialsData,
'postsData': completePostsList
});
}
catch (error) {
Expand Down
46 changes: 39 additions & 7 deletions src/controllers/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1100,9 +1100,6 @@ usersRoutes.get('/fetchFeed', async (req, res) => {
const fetchFollowingData = await postsClient.query(fetchFollowingDataQuery, [
userID, 0, maxFetchLimit, username, IP, PORT, password
]);
for(var i = 0; i < 50; i++){

}
const feedPosts : String[] = fetchFollowingData.rows.map((e) => e.post_data);
const totalPostsLength = Math.min(maxFetchLimit, feedPosts.length);
var modifiedFeedPosts = [...feedPosts];
Expand All @@ -1119,7 +1116,6 @@ usersRoutes.get('/fetchFeed', async (req, res) => {
usersSocialsData.push(currentUserCompleteData.data.socials_data);
}


res.json({
'message': "Successfully fetched data",
'usersProfileData': usersProfileData,
Expand Down Expand Up @@ -2408,7 +2404,7 @@ usersRoutes.get('/fetchSearchedUsers', async (req, res) => {
} = req.body;

try{
const fetchSearchedUsersDataQuery = `SELECT user_id FROM basic_data.user_profile WHERE lower(name) LIKE '%lower(${searchedText})%' OR username LIKE '%lower(${searchedText})%'`;
const fetchSearchedUsersDataQuery = `SELECT user_id FROM basic_data.user_profile WHERE name LIKE '%${searchedText}%' OR username LIKE '%${searchedText}%'`;
const fetchSearchedUsersData = await profilesClient.query(fetchSearchedUsersDataQuery, []);
var searchedUsersData : String[] = fetchSearchedUsersData.rows.map((e) => e.user_id);
const totalUsersLength = searchedUsersData.length;
Expand Down Expand Up @@ -2758,19 +2754,55 @@ usersRoutes.get('/fetchSearchedTagUsers', async (req, res) => {
}
});

usersRoutes.get('/fetchTopHashtags', async (req, res) => {
usersRoutes.get('/fetchTopData', async (req, res) => {
const {
currentID,
paginationLimit
} = req.body;

try{

const fetchTopPostsQuery = `SELECT * FROM public."fetch_most_popular_posts"($1, $2, $3, $4, $5, $6)`;
const fetchTopPosts = await postsClient.query(fetchTopPostsQuery, [
currentID, paginationLimit,
username, IP, PORT, password
]);
const postsList : String[] = fetchTopPosts.rows.map((e) => e.post_data);
var getCompletePostsData = await getPostsListFilteredData(postsList, currentID);
const completePostsList = getCompletePostsData.completeDataList;

const fetchTopUsersQuery = `SELECT * FROM public."fetch_most_popular_users"($1, $2)`;
const fetchTopUsers = await profilesClient.query(fetchTopUsersQuery, [currentID, paginationLimit]);
const usersID : String[] = fetchTopUsers.rows.map((e) => e.user_id);
var getCompleteUsersData = await getUsersListFilteredData(usersID, currentID);

var combinedUsersID : any[] = [];
var combinedUsersProfileData : any[] = [...getCompleteUsersData.usersProfileData, ...getCompletePostsData.usersProfileData];
var combinedUsersSocialsData = [...getCompleteUsersData.usersSocialsData, ...getCompletePostsData.usersSocialsData];
var filteredUsersProfileData = [];
var filteredUsersSocialsData = [];

for(var i = 0; i < combinedUsersProfileData.length; i++){
if(!combinedUsersID.includes(combinedUsersProfileData[i].user_id)){
combinedUsersID.push(combinedUsersProfileData[i].user_id);
filteredUsersProfileData.push(combinedUsersProfileData[i]);
filteredUsersSocialsData.push(combinedUsersSocialsData[i]);
}
}

const usersProfileData = filteredUsersProfileData;
const usersSocialsData = filteredUsersSocialsData;

const fetchHashtagsDataQuery = `SELECT * FROM hashtags.hashtags_list ORDER BY hashtag_count DESC OFFSET $1 LIMIT $2`;
const fetchHashtagsData = await keywordsClient.query(fetchHashtagsDataQuery, [0, paginationLimit]);
const hashtagsData : String[] = fetchHashtagsData.rows;

res.json({
'message': "Successfully fetched hashtags data",
'hashtagsData': hashtagsData
'hashtagsData': hashtagsData,
'usersProfileData': usersProfileData,
'usersSocialsData': usersSocialsData,
'postsData': completePostsList
})
} catch (error) {
console.error('Error fetching hashtags data:', error);
Expand Down
15 changes: 15 additions & 0 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": 2,
"builds": [
{
"src": "index.js",
"use": "@vercel/node"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "index.js"
}
]
}

0 comments on commit e3d11da

Please sign in to comment.