Testing and debugging

This commit is contained in:
Andrew Trieu
2023-07-23 18:56:27 +03:00
parent cd8c4611b6
commit 2e1832a0bf
16 changed files with 61 additions and 52 deletions

View File

@@ -71,12 +71,12 @@ export const login = async (req, res) => {
const validPassword = await bcrypt.compare(password, user.password);
if (!validPassword) return res.status(400).json({ msg: "Wrong password" });
const accessToken = jwt.sign(
const token = jwt.sign(
{ id: user._id, admin: user.admin },
process.env.JWT_SECRET
);
delete user.password;
res.status(200).json({ accessToken, user });
res.status(200).json({ token, user });
} catch (error) {
res.status(500).json({ error: error.message });
}

View File

@@ -55,6 +55,9 @@ export const getFriends = async (req, res) => {
export const patchFriend = async (req, res) => {
try {
const { userId, friendId } = req.params;
if (userId === friendId) {
return res.status(400).json({ error: "You cannot add yourself" });
}
const user = await User.findById(userId);
const friend = await User.findById(friendId);
@@ -63,7 +66,7 @@ export const patchFriend = async (req, res) => {
friend.friends = friend.friends.filter((id) => id !== id);
} else {
user.friends.push(friendId);
friend.friends.push(id);
friend.friends.push(userId);
}
await user.save();

View File

@@ -36,7 +36,7 @@ export const mockUsers = [
firstName: "Aake",
lastName: "Haapala",
email: "aake.haapala@mail.com",
password: "$2a$04$LzaBXTtLrOglvkHIPcAYKevvIOLoPZCm48DdQr.rf1gg5cIiehV4e", // 123456##
password: "$2b$04$EYpcRcVBZP35DXZdQbXWSec1Mxh.H3HXqPRBYhjIw1/WXcadzmiti", // 123456##
profilePicturePath: "p1.jpeg",
friends: [],
location: "Helsinki, Finland",
@@ -51,7 +51,7 @@ export const mockUsers = [
firstName: "Eelis",
lastName: "Janhunen",
email: "eelis.janhunen@mail.com",
password: "$2a$04$LzaBXTtLrOglvkHIPcAYKevvIOLoPZCm48DdQr.rf1gg5cIiehV4e9",
password: "$2b$04$EYpcRcVBZP35DXZdQbXWSec1Mxh.H3HXqPRBYhjIw1/WXcadzmiti",
profilePicturePath: "p2.jpeg",
friends: [],
location: "Hämeenlinna, Finland",
@@ -66,7 +66,7 @@ export const mockUsers = [
firstName: "Eevert",
lastName: "Kotilainen",
email: "evert.kotilainen@mail.com",
password: "$2a$04$LzaBXTtLrOglvkHIPcAYKevvIOLoPZCm48DdQr.rf1gg5cIiehV4e",
password: "$2b$04$EYpcRcVBZP35DXZdQbXWSec1Mxh.H3HXqPRBYhjIw1/WXcadzmiti",
profilePicturePath: "p3.jpeg",
friends: [],
location: "Kerava, Finland",
@@ -81,7 +81,7 @@ export const mockUsers = [
firstName: "Krista",
lastName: "Manninen",
email: "krista.manninen@mail.com",
password: "$2a$04$LzaBXTtLrOglvkHIPcAYKevvIOLoPZCm48DdQr.rf1gg5cIiehV4e",
password: "$2b$04$EYpcRcVBZP35DXZdQbXWSec1Mxh.H3HXqPRBYhjIw1/WXcadzmiti",
profilePicturePath: "p4.jpeg",
friends: [],
location: "Espoo, Finland",
@@ -96,7 +96,7 @@ export const mockUsers = [
firstName: "Taina",
lastName: "Ruotsalainen",
email: "taina.ruotsalainen@mail.com",
password: "$2a$04$LzaBXTtLrOglvkHIPcAYKevvIOLoPZCm48DdQr.rf1gg5cIiehV4e",
password: "$2b$04$EYpcRcVBZP35DXZdQbXWSec1Mxh.H3HXqPRBYhjIw1/WXcadzmiti",
profilePicturePath: "p5.jpeg",
friends: [],
location: "Turku, Finland",
@@ -111,7 +111,7 @@ export const mockUsers = [
firstName: "Lea",
lastName: "Varis",
email: "lea.varis@mail.com",
password: "$2a$04$LzaBXTtLrOglvkHIPcAYKevvIOLoPZCm48DdQr.rf1gg5cIiehV4e",
password: "$2b$04$EYpcRcVBZP35DXZdQbXWSec1Mxh.H3HXqPRBYhjIw1/WXcadzmiti",
profilePicturePath: "p6.jpeg",
friends: [],
location: "Tampere, Finland",
@@ -126,7 +126,7 @@ export const mockUsers = [
firstName: "Elisa",
lastName: "Järvelä",
email: "elisa.jarvela@mail.com",
password: "$2a$04$LzaBXTtLrOglvkHIPcAYKevvIOLoPZCm48DdQr.rf1gg5cIiehV4e",
password: "$2b$04$EYpcRcVBZP35DXZdQbXWSec1Mxh.H3HXqPRBYhjIw1/WXcadzmiti",
profilePicturePath: "p7.jpeg",
friends: [],
location: "Riihimäki, Finland",
@@ -141,7 +141,7 @@ export const mockUsers = [
firstName: "Joonas",
lastName: "Koivisto",
email: "joonas.koivisto@mail.com",
password: "$2a$04$LzaBXTtLrOglvkHIPcAYKevvIOLoPZCm48DdQr.rf1gg5cIiehV4e",
password: "$2b$04$EYpcRcVBZP35DXZdQbXWSec1Mxh.H3HXqPRBYhjIw1/WXcadzmiti",
profilePicturePath: "p8.jpeg",
friends: [],
location: "Rovaniemi, Finland",
@@ -156,7 +156,7 @@ export const mockUsers = [
firstName: "Johanna",
lastName: "Mäkinen",
email: "johanna.makinen@mail.com",
password: "$2a$04$LzaBXTtLrOglvkHIPcAYKevvIOLoPZCm48DdQr.rf1gg5cIiehV4e",
password: "$2b$04$EYpcRcVBZP35DXZdQbXWSec1Mxh.H3HXqPRBYhjIw1/WXcadzmiti",
profilePicturePath: "p9.jpeg",
friends: [],
location: "Oulu, Finland",
@@ -171,7 +171,7 @@ export const mockUsers = [
firstName: "Johannes",
lastName: "Korhonen",
email: "johannes.korhonen@mail.com",
password: "$2a$04$LzaBXTtLrOglvkHIPcAYKevvIOLoPZCm48DdQr.rf1gg5cIiehV4e",
password: "$2b$04$EYpcRcVBZP35DXZdQbXWSec1Mxh.H3HXqPRBYhjIw1/WXcadzmiti",
profilePicturePath: "p10.jpeg",
friends: [],
location: "Kuopio, Finland",
@@ -186,7 +186,7 @@ export const mockUsers = [
firstName: "Mikko",
lastName: "Koivu",
email: "mikko.koivu@mail.com",
password: "$2a$04$LzaBXTtLrOglvkHIPcAYKevvIOLoPZCm48DdQr.rf1gg5cIiehV4e",
password: "$2b$04$EYpcRcVBZP35DXZdQbXWSec1Mxh.H3HXqPRBYhjIw1/WXcadzmiti",
profilePicturePath: "p11.jpeg",
friends: [],
location: "Jyväskylä, Finland",