-
Notifications
You must be signed in to change notification settings - Fork 0
/
userSearchRelatedTransactions.js
74 lines (70 loc) · 2.12 KB
/
userSearchRelatedTransactions.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
import { pool } from "./server.js";
export const userPostCount = (request) => {
return new Promise((res, rej) => {
// res("Hey accepte")
rej(new Error("Sorry we are unable to conduct the res"));
});
};
export const checkUserFollow = (req) => {
const { follow_user, followed_user } = req.query;
console.log(follow_user, followed_user);
return new Promise((resolve, reject) => {
pool.query(
"SELECT * FROM followers WHERE follower_id = $1 AND followed_id = $2",
[follow_user, followed_user],
(err, result) => {
if (err) {
reject(err);
} else {
// If the result contains rows, it means the follow_user has followed the followed_user
const followed = result.rows.length > 0;
resolve(followed);
}
}
);
});
};
export const followUser = (req) => {
const { follower_id, followed_id } = req.query;
console.log(follower_id, followed_id);
return new Promise((resolve, reject) => {
pool.query(
"INSERT INTO followers (follower_id,followed_id ) VALUES ($1,$2) RETURNING *",
[follower_id, followed_id],
(err, result) => {
if (err) {
reject(err);
} else {
// If the result contains rows, it means the follow_user has followed the followed_user
const followed = {
message: "User Successfully Followed",
followed: true,
};
resolve(followed);
}
}
);
});
};
export const unfollowUser = (req) => {
const { follower_id, followed_id } = req.query;
console.log(follower_id, followed_id);
return new Promise((resolve, reject) => {
pool.query(
"DELETE FROM followers WHERE follower_id = $1 AND followed_id = $2 RETURNING *",
[follower_id, followed_id],
(err, result) => {
if (err) {
reject(err);
} else {
// If the result contains rows, it means the row was successfully deleted
const unfollowed = {
message: "User Successfully Unfollowed",
unfollowed: true,
};
resolve(unfollowed);
}
}
);
});
};