Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b8c1749

Browse files
committed
Block System fixed
1 parent d90c2cd commit b8c1749

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

‎src/controllers/User/Block/blockUser.js‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11

22
/**
33
* @module Block User Controller
4-
*
4+
*
55
* @param {Request} req - HTTP Request from the client
66
* @param {Response} res - HTTP Response for the client
7-
*
7+
*
88
* @description
99
* This controller will allow the user to block a specific user, if all parameters are correct.
10-
*
10+
*
1111
* @todo
1212
* Nothing for now.
1313
*/
@@ -40,11 +40,14 @@ module.exports.blockUser = async (req, res) => {
4040
if (!user) {
4141
return res.status(404).send({ msg: 'Current account not found.' })
4242
}
43-
if (user.hasBlocked(userToBlock)) {
43+
44+
const alreadyBlocked = await user.hasBlockedUser(userToBlock);
45+
46+
if (alreadyBlocked) {
4447
return res.status(400).send({ msg: 'You have already blocked this person.' });
4548
}
4649

47-
user.addBlocked(userToBlock);
50+
user.addBlockedUser(userToBlock);
4851

4952
return res.status(200).send({ msg: 'User blocked.' });
5053

‎src/controllers/User/Block/listBlocked.js‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,19 @@ module.exports.listBlocked = async (req, res) => {
1919

2020
try {
2121

22-
const user = await User.findOne({
22+
const userBlockedList = await User.findOne({
2323
where: {
2424
id: req.user.id,
2525
},
26-
})
26+
include: 'BlockedUser',
27+
});
2728

2829
if (!user) {
2930
return res.status(404).send({ msg: 'User not found.' });
3031
}
3132

32-
constblockedUsers=awaituser.getBlocked();
33-
return res.status(200).json(blockedUsers);
33+
34+
return res.status(200).json(userBlockedList.BlockedUser);
3435

3536
} catch (err) {
3637
console.log(err.message);

‎src/controllers/User/Block/queryBlock.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module.exports.queryBlock = async (req, res) => {
2323
const [blockedUser, user] = await Promise.all([
2424
User.findOne({
2525
where: {
26-
id: req.params.blockId,
26+
id: req.params.blockedId,
2727
},
2828
})
2929
,
@@ -41,7 +41,9 @@ module.exports.queryBlock = async (req, res) => {
4141
return res.status(404).send({ msg: 'Current account not found. Try loggin in.' })
4242
}
4343

44-
if (!user.hasBlocked(blockedUser)) {
44+
const alreadyBlocked = await user.hasBlockedUser(blockedUser);
45+
46+
if (!alreadyBlocked) {
4547
return res.status(401).send({ msg: "You have not blocked this person." });
4648
}
4749

‎src/controllers/User/Block/unblockUser.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@ module.exports.unblockUser = async (req, res) => {
4343
return res.status(404).send({ msg: 'Current account not found.' });
4444
}
4545

46-
if (!user.hasBlocked(blockedUser)) {
46+
const alreadyBlocked = await user.hasBlockedUser(blockedUser);
47+
48+
if (!alreadyBlocked) {
4749
return res.status(401).send({ msg: "You have not blocked this person." });
4850
}
4951

50-
user.removeBlocked(blockedUser);
52+
user.removeBlockedUser(blockedUser);
5153

5254
return res.status(200).send({ msg: 'User unblocked.' });
5355

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /