Skip to content

Commit

Permalink
fb
Browse files Browse the repository at this point in the history
  • Loading branch information
Dobrunia committed Nov 18, 2023
1 parent 8699b0b commit ea4e838
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
8 changes: 6 additions & 2 deletions controlers/user-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
isInfoExist,
createUserInfo,
getMyInfo,
getnewMessagesNotifications,
} from '../services/user-service.js';
import { emailVerification } from '../services/mail-service.js';
import { config } from '../config.js';
Expand Down Expand Up @@ -251,10 +252,13 @@ class UserController {
}
async getNotifications(request, response, next) {
try {
const users_response = await getFriendsRequestNotifications(
const friends_requests = await getFriendsRequestNotifications(
request.user.id,
);
response.json(users_response);
const new_messages_requests = await getnewMessagesNotifications(
request.user.id,
);
response.json(friends_requests.concat(new_messages_requests));
} catch (error) {
next(error);
}
Expand Down
17 changes: 17 additions & 0 deletions services/sqlwrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,23 @@ export async function FriendsRequestNotifications(
}
}

export async function newMessagesNotifications(
myId: string,
): Promise<mysql.RowDataPacket[]> {
try {
const results = await conn.query<mysql.RowDataPacket[]>(
`SELECT *
FROM new_massage_notifications
JOIN users ON users.id = new_massage_notifications.user_id_from
WHERE new_massage_notifications.user_id_to = ?`,
[myId],
);
return results[0];
} catch (ex) {
console.log(ex);
}
}

export async function findFriendStatusInfo(
myId: string,
userId: string,
Expand Down
5 changes: 5 additions & 0 deletions services/user-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
returnAllUserPost,
findUserInfoById,
createUserInfoTable,
newMessagesNotifications,
} from './sqlwrapper.js';
import { generateJwtTokens, validateRefreshToken } from './token-service.js';
import bcrypt from 'bcryptjs';
Expand Down Expand Up @@ -320,6 +321,10 @@ export async function getFriendsRequestNotifications(myId: string) {
return await FriendsRequestNotifications(myId);
}

export async function getnewMessagesNotifications(myId: string) {
return await newMessagesNotifications(myId);
}

export async function getFriendStatusInfo(myId: string, userId: string) {
return await findFriendStatusInfo(myId, userId);
}
Expand Down

0 comments on commit ea4e838

Please sign in to comment.