Add mock data + Fix package.json not pushed + Add REST requests
This commit is contained in:
committed by
Andrew Trieu
parent
a25ea2d90a
commit
f3d5ce2524
@@ -11,4 +11,6 @@ Table:
|
||||
| 07.07.2023 | Authentication and authorization | 6 |
|
||||
| 10.07.2023 | User routes | 4 |
|
||||
| 11.07.2023 | Post routes | 6 |
|
||||
| 11.07.2023 | Add mock data + Fix package.json not pushed | 2 |
|
||||
| 11.07.2023 | Add REST requests | 1 |
|
||||
|
||||
|
||||
@@ -79,3 +79,4 @@ export const likePost = async (req, res) => {
|
||||
res.status(404).json({ error: error.message });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import User from "../models/User";
|
||||
import User from "../models/User.js";
|
||||
|
||||
/**
|
||||
* Read - GET
|
||||
|
||||
334
server/data/mock.js
Normal file
334
server/data/mock.js
Normal file
@@ -0,0 +1,334 @@
|
||||
import mongoose from "mongoose";
|
||||
|
||||
const userIds = [
|
||||
new mongoose.Types.ObjectId(),
|
||||
new mongoose.Types.ObjectId(),
|
||||
new mongoose.Types.ObjectId(),
|
||||
new mongoose.Types.ObjectId(),
|
||||
new mongoose.Types.ObjectId(),
|
||||
new mongoose.Types.ObjectId(),
|
||||
new mongoose.Types.ObjectId(),
|
||||
new mongoose.Types.ObjectId(),
|
||||
new mongoose.Types.ObjectId(),
|
||||
new mongoose.Types.ObjectId(),
|
||||
new mongoose.Types.ObjectId(),
|
||||
new mongoose.Types.ObjectId(),
|
||||
];
|
||||
|
||||
export const mockUsers = [
|
||||
{
|
||||
_id: userIds[0],
|
||||
firstName: "super",
|
||||
lastName: "admin",
|
||||
email: "admin@chathive.com",
|
||||
password: "$2a$04$3OEpXZDLOknUHeooBwYfFOe4u2sFkNTqvHqQBmcPRWze5Q3UnY7ze", // admin
|
||||
profilePicturePath: "admin.jpeg",
|
||||
friends: [],
|
||||
location: "Lahti, Finland",
|
||||
description: "I am the admin",
|
||||
admin: true,
|
||||
createdAt: 946717200,
|
||||
updatedAt: 946717200,
|
||||
__v: 0,
|
||||
},
|
||||
{
|
||||
_id: userIds[1],
|
||||
firstName: "Aake",
|
||||
lastName: "Haapala",
|
||||
email: "aake.haapala@mail.com",
|
||||
password: "$2a$04$LzaBXTtLrOglvkHIPcAYKevvIOLoPZCm48DdQr.rf1gg5cIiehV4e", // 123456##
|
||||
profilePicturePath: "p1.jpeg",
|
||||
friends: [],
|
||||
location: "Helsinki, Finland",
|
||||
description: "I am a software developer",
|
||||
admin: false,
|
||||
createdAt: 946717200,
|
||||
updatedAt: 946717200,
|
||||
__v: 0,
|
||||
},
|
||||
{
|
||||
_id: userIds[2],
|
||||
firstName: "Eelis",
|
||||
lastName: "Janhunen",
|
||||
email: "eelis.janhunen@mail.com",
|
||||
password: "$2a$04$LzaBXTtLrOglvkHIPcAYKevvIOLoPZCm48DdQr.rf1gg5cIiehV4e9",
|
||||
profilePicturePath: "p2.jpeg",
|
||||
friends: [],
|
||||
location: "Hämeenlinna, Finland",
|
||||
description: "I am an accountant",
|
||||
admin: false,
|
||||
createdAt: 946717200,
|
||||
updatedAt: 946717200,
|
||||
__v: 0,
|
||||
},
|
||||
{
|
||||
_id: userIds[3],
|
||||
firstName: "Eevert",
|
||||
lastName: "Kotilainen",
|
||||
email: "evert.kotilainen@mail.com",
|
||||
password: "$2a$04$LzaBXTtLrOglvkHIPcAYKevvIOLoPZCm48DdQr.rf1gg5cIiehV4e",
|
||||
profilePicturePath: "p3.jpeg",
|
||||
friends: [],
|
||||
location: "Kerava, Finland",
|
||||
description: "I am a teacher",
|
||||
admin: false,
|
||||
createdAt: 946717200,
|
||||
updatedAt: 946717200,
|
||||
__v: 0,
|
||||
},
|
||||
{
|
||||
_id: userIds[4],
|
||||
firstName: "Krista",
|
||||
lastName: "Manninen",
|
||||
email: "krista.manninen@mail.com",
|
||||
password: "$2a$04$LzaBXTtLrOglvkHIPcAYKevvIOLoPZCm48DdQr.rf1gg5cIiehV4e",
|
||||
profilePicturePath: "p4.jpeg",
|
||||
friends: [],
|
||||
location: "Espoo, Finland",
|
||||
description: "I am a nurse",
|
||||
admin: false,
|
||||
createdAt: 946717200,
|
||||
updatedAt: 946717200,
|
||||
__v: 0,
|
||||
},
|
||||
{
|
||||
_id: userIds[5],
|
||||
firstName: "Taina",
|
||||
lastName: "Ruotsalainen",
|
||||
email: "taina.ruotsalainen@mail.com",
|
||||
password: "$2a$04$LzaBXTtLrOglvkHIPcAYKevvIOLoPZCm48DdQr.rf1gg5cIiehV4e",
|
||||
profilePicturePath: "p5.jpeg",
|
||||
friends: [],
|
||||
location: "Turku, Finland",
|
||||
description: "I am a doctor",
|
||||
admin: false,
|
||||
createdAt: 946717200,
|
||||
updatedAt: 946717200,
|
||||
__v: 0,
|
||||
},
|
||||
{
|
||||
_id: userIds[6],
|
||||
firstName: "Lea",
|
||||
lastName: "Varis",
|
||||
email: "lea.varis@mail.com",
|
||||
password: "$2a$04$LzaBXTtLrOglvkHIPcAYKevvIOLoPZCm48DdQr.rf1gg5cIiehV4e",
|
||||
profilePicturePath: "p6.jpeg",
|
||||
friends: [],
|
||||
location: "Tampere, Finland",
|
||||
description: "I am a data scientist",
|
||||
admin: false,
|
||||
createdAt: 946717200,
|
||||
updatedAt: 946717200,
|
||||
__v: 0,
|
||||
},
|
||||
{
|
||||
_id: userIds[7],
|
||||
firstName: "Elisa",
|
||||
lastName: "Järvelä",
|
||||
email: "elisa.jarvela@mail.com",
|
||||
password: "$2a$04$LzaBXTtLrOglvkHIPcAYKevvIOLoPZCm48DdQr.rf1gg5cIiehV4e",
|
||||
profilePicturePath: "p7.jpeg",
|
||||
friends: [],
|
||||
location: "Riihimäki, Finland",
|
||||
description: "I am a shopkeeper",
|
||||
admin: false,
|
||||
createdAt: 946717200,
|
||||
updatedAt: 946717200,
|
||||
__v: 0,
|
||||
},
|
||||
{
|
||||
_id: userIds[8],
|
||||
firstName: "Joonas",
|
||||
lastName: "Koivisto",
|
||||
email: "joonas.koivisto@mail.com",
|
||||
password: "$2a$04$LzaBXTtLrOglvkHIPcAYKevvIOLoPZCm48DdQr.rf1gg5cIiehV4e",
|
||||
profilePicturePath: "p8.jpeg",
|
||||
friends: [],
|
||||
location: "Rovaniemi, Finland",
|
||||
description: "I am a student",
|
||||
admin: false,
|
||||
createdAt: 946717200,
|
||||
updatedAt: 946717200,
|
||||
__v: 0,
|
||||
},
|
||||
{
|
||||
_id: userIds[9],
|
||||
firstName: "Johanna",
|
||||
lastName: "Mäkinen",
|
||||
email: "johanna.makinen@mail.com",
|
||||
password: "$2a$04$LzaBXTtLrOglvkHIPcAYKevvIOLoPZCm48DdQr.rf1gg5cIiehV4e",
|
||||
profilePicturePath: "p9.jpeg",
|
||||
friends: [],
|
||||
location: "Oulu, Finland",
|
||||
description: "I am a researcher",
|
||||
admin: false,
|
||||
createdAt: 946717200,
|
||||
updatedAt: 946717200,
|
||||
__v: 0,
|
||||
},
|
||||
{
|
||||
_id: userIds[10],
|
||||
firstName: "Johannes",
|
||||
lastName: "Korhonen",
|
||||
email: "johannes.korhonen@mail.com",
|
||||
password: "$2a$04$LzaBXTtLrOglvkHIPcAYKevvIOLoPZCm48DdQr.rf1gg5cIiehV4e",
|
||||
profilePicturePath: "p10.jpeg",
|
||||
friends: [],
|
||||
location: "Kuopio, Finland",
|
||||
description: "I am an athlete",
|
||||
admin: false,
|
||||
createdAt: 946717200,
|
||||
updatedAt: 946717200,
|
||||
__v: 0,
|
||||
},
|
||||
{
|
||||
_id: userIds[11],
|
||||
firstName: "Mikko",
|
||||
lastName: "Koivu",
|
||||
email: "mikko.koivu@mail.com",
|
||||
password: "$2a$04$LzaBXTtLrOglvkHIPcAYKevvIOLoPZCm48DdQr.rf1gg5cIiehV4e",
|
||||
profilePicturePath: "p11.jpeg",
|
||||
friends: [],
|
||||
location: "Jyväskylä, Finland",
|
||||
description: "I am a hockey player",
|
||||
admin: false,
|
||||
createdAt: 946717200,
|
||||
updatedAt: 946717200,
|
||||
__v: 0,
|
||||
},
|
||||
];
|
||||
|
||||
export const mockPosts = [
|
||||
{
|
||||
_id: new mongoose.Types.ObjectId(),
|
||||
userId: userIds[1],
|
||||
firstName: "Aake",
|
||||
lastName: "Haahpala",
|
||||
location: "Helsinki, Finland",
|
||||
description: "Just moved!",
|
||||
contentPicturePath: "post1.jpeg",
|
||||
profilePicturePath: "p1.jpeg",
|
||||
likes: new Map([
|
||||
[userIds[2], true],
|
||||
[userIds[3], true],
|
||||
[userIds[4], true],
|
||||
[userIds[5], true],
|
||||
]),
|
||||
comments: ["Congrats!", "Nice!", "Good luck!"],
|
||||
},
|
||||
{
|
||||
_id: new mongoose.Types.ObjectId(),
|
||||
userId: userIds[3],
|
||||
firstName: "Eevert",
|
||||
lastName: "Kotilainen",
|
||||
location: "Kainuu, Finland",
|
||||
description:
|
||||
"Summer is coming! I am so excited to go to the cottage and enjoy the nature.",
|
||||
contentPicturePath: "post2.jpeg",
|
||||
profilePicturePath: "p3.jpeg",
|
||||
likes: new Map([
|
||||
[userIds[7], true],
|
||||
[userIds[4], true],
|
||||
[userIds[1], true],
|
||||
[userIds[2], true],
|
||||
]),
|
||||
comments: [
|
||||
"It's so beautiful there!",
|
||||
"I wish I could go there too!",
|
||||
"Have fun!",
|
||||
"Don't forget to take pictures!",
|
||||
],
|
||||
},
|
||||
{
|
||||
_id: new mongoose.Types.ObjectId(),
|
||||
userId: userIds[5],
|
||||
firstName: "Taina",
|
||||
lastName: "Ruotsalainen",
|
||||
location: "Berlin, Germany",
|
||||
description:
|
||||
"International conference in Berlin! I am so excited to meet new people and learn new things.",
|
||||
contentPicturePath: "post3.jpeg",
|
||||
profilePicturePath: "p5.jpeg",
|
||||
likes: new Map([
|
||||
[userIds[1], true],
|
||||
[userIds[6], true],
|
||||
[userIds[3], true],
|
||||
[userIds[4], true],
|
||||
]),
|
||||
comments: [
|
||||
"Another achievement!",
|
||||
"You are so talented!",
|
||||
"I am so proud of you!",
|
||||
"You rock!",
|
||||
],
|
||||
},
|
||||
{
|
||||
_id: new mongoose.Types.ObjectId(),
|
||||
userId: userIds[7],
|
||||
firstName: "Elisa",
|
||||
lastName: "Järvelä",
|
||||
location: "Riihimäki, Finland",
|
||||
description:
|
||||
"Taking care of my garden. I am so excited to see the flowers bloom!",
|
||||
contentPicturePath: "post4.jpeg",
|
||||
profilePicturePath: "p7.jpeg",
|
||||
likes: new Map([
|
||||
[userIds[1], true],
|
||||
[userIds[6], true],
|
||||
[userIds[3], true],
|
||||
[userIds[4], true],
|
||||
]),
|
||||
comments: [
|
||||
"Beautiful!",
|
||||
"I wish I had a garden too!",
|
||||
"I love flowers!",
|
||||
"Nice!",
|
||||
],
|
||||
},
|
||||
{
|
||||
_id: new mongoose.Types.ObjectId(),
|
||||
userId: userIds[9],
|
||||
firstName: "Johanna",
|
||||
lastName: "Mäkinen",
|
||||
location: "Haparanda, Sweden",
|
||||
description:
|
||||
"A trip to neighboring Sweden! I am so excited to try some meatballs!",
|
||||
contentPicturePath: "post5.jpeg",
|
||||
profilePicturePath: "p9.jpeg",
|
||||
likes: new Map([
|
||||
[userIds[1], true],
|
||||
[userIds[3], true],
|
||||
[userIds[5], true],
|
||||
[userIds[7], true],
|
||||
]),
|
||||
comments: [
|
||||
"I went there last year!",
|
||||
"It was so much fun!",
|
||||
"I hope you have a great time!",
|
||||
"Bring me some meatballs!",
|
||||
],
|
||||
},
|
||||
{
|
||||
_id: new mongoose.Types.ObjectId(),
|
||||
userId: userIds[11],
|
||||
firstName: "Mikko",
|
||||
lastName: "Koivu",
|
||||
location: "Mikkeli, Finland",
|
||||
description:
|
||||
"Student excursion to Mikkeli! I am so excited to make new friends and drink some beer!",
|
||||
contentPicturePath: "post6.jpeg",
|
||||
profilePicturePath: "p11.jpeg",
|
||||
likes: new Map([
|
||||
[userIds[1], true],
|
||||
[userIds[2], true],
|
||||
[userIds[3], true],
|
||||
[userIds[4], true],
|
||||
]),
|
||||
comments: [
|
||||
"Don't drink too much!",
|
||||
"My kids study there!",
|
||||
"Explore the city!",
|
||||
"Stay safe!",
|
||||
],
|
||||
},
|
||||
];
|
||||
2
server/debug/get_feed.rest
Normal file
2
server/debug/get_feed.rest
Normal file
@@ -0,0 +1,2 @@
|
||||
GET localhost:3001/posts/
|
||||
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY0YWRhMGMzNWZjYmJmNmI4YzI0ZGZkMSIsImFkbWluIjp0cnVlLCJpYXQiOjE2ODkxMDIwNzF9.YmbSFv4q6sTRqw0bvxQN-dBiKElEY8NcGeIKqu6B0lw
|
||||
2
server/debug/get_user.rest
Normal file
2
server/debug/get_user.rest
Normal file
@@ -0,0 +1,2 @@
|
||||
GET localhost:3001/users/64ada0c35fcbbf6b8c24dfd2
|
||||
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY0YWRhMGMzNWZjYmJmNmI4YzI0ZGZkMSIsImFkbWluIjp0cnVlLCJpYXQiOjE2ODkxMDIwNzF9.YmbSFv4q6sTRqw0bvxQN-dBiKElEY8NcGeIKqu6B0lw
|
||||
6
server/debug/login.rest
Normal file
6
server/debug/login.rest
Normal file
@@ -0,0 +1,6 @@
|
||||
POST localhost:3001/auth/login
|
||||
|
||||
{
|
||||
"email": "admin@chathive.com",
|
||||
"password": "admin"
|
||||
}
|
||||
1
server/debug/register.rest
Normal file
1
server/debug/register.rest
Normal file
@@ -0,0 +1 @@
|
||||
POST localhost:3001/users/
|
||||
@@ -17,6 +17,10 @@ import { register } from "./controllers/auth.js";
|
||||
import { createPost } from "./controllers/posts.js";
|
||||
/* Middlewares */
|
||||
import { verifyToken } from "./middlewares/auth.js";
|
||||
/* Models */
|
||||
import User from "./models/User.js";
|
||||
import Post from "./models/Post.js";
|
||||
import { mockUsers, mockPosts } from "./data/mock.js";
|
||||
|
||||
/**
|
||||
* Config
|
||||
@@ -65,7 +69,11 @@ mongoose
|
||||
useNewUrlParser: true,
|
||||
useUnifiedTopology: true,
|
||||
})
|
||||
.then(() =>
|
||||
app.listen(PORT, () => console.log(`Server running on port: ${PORT}`))
|
||||
)
|
||||
.then(() => {
|
||||
app.listen(PORT, () => console.log(`Server running on port: ${PORT}`));
|
||||
|
||||
/* Inject mock data - DO NOT USE IN PRODUCTION */
|
||||
// User.insertMany(mockUsers).then(() => console.log("Mock users injected"));
|
||||
// Post.insertMany(mockPosts).then(() => console.log("Mock posts injected"));
|
||||
})
|
||||
.catch((error) => console.log(error.message));
|
||||
|
||||
2271
server/package-lock.json
generated
2271
server/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,14 +1,28 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"gridfs-stream": "^1.1.1"
|
||||
"bcrypt": "^5.1.0",
|
||||
"body-parser": "^1.20.2",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^16.3.1",
|
||||
"express": "^4.18.2",
|
||||
"gridfs-stream": "^1.1.1",
|
||||
"helmet": "^7.0.0",
|
||||
"jsonwebtoken": "^9.0.1",
|
||||
"mongoose": "^7.3.2",
|
||||
"morgan": "^1.10.0",
|
||||
"multer": "^1.4.4",
|
||||
"multer-gridfs-storage": "^5.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^2.0.12"
|
||||
},
|
||||
"type": "module",
|
||||
"name": "server",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"devDependencies": {},
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"start": "nodemon index.js"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
|
||||
@@ -14,3 +14,5 @@ router.get("/:userId", verifyToken, getUserPosts);
|
||||
* Update - PATCH
|
||||
*/
|
||||
router.patch("/:postId/like", verifyToken, likePost);
|
||||
|
||||
export default router;
|
||||
|
||||
Reference in New Issue
Block a user