diff --git a/api/controllers/post.js b/api/controllers/post.js index 7ce8dd5..a171a48 100644 --- a/api/controllers/post.js +++ b/api/controllers/post.js @@ -90,13 +90,29 @@ exports.makePost = (req,res) => { const dir = 'assets/' + req.body.author + '/posts/' + title + '_' + Date.now() + '/images/'; let imageArray = null; + + let items = null; + + // please comment out this part if nag-error sa paggawa ng post + if(req.body.items && req.body.items.length > 0){ + items = req.body.items.map(item => { + console.log(item); + const newItem = new Item({ + name : item.name, + amount : item.amount, + total : item.total + }); + return newItem; + }); + } + // _____________________________ + if(req.files && req.files.length > 1){ imageArray = req.files.map(file =>{ image = new Image({ _id: new mongoose.Types.ObjectId(), - total: req.body.total, image: { imageName : file.filename, url: 'http://localhost:5000/'+dir+file.filename @@ -105,8 +121,7 @@ exports.makePost = (req,res) => { return(image) }) - } - + } const post = new Post({ _id: new mongoose.Types.ObjectId(), @@ -116,7 +131,7 @@ exports.makePost = (req,res) => { type : req.body.type, status : req.body.status, description : req.body.description, - items : [], + items : items, location : req.body.location, tags : req.body.tags, datePosted : Date.now(), @@ -125,7 +140,7 @@ exports.makePost = (req,res) => { comments : [] }) - // There is images and needs to create folders and move images + // There are images therefore it needs to create folders and move images if(req.files.length > 0){ fs.move('./uploads',dir,(error)=>{ @@ -323,6 +338,7 @@ exports.deletePost = (req,res) => { .exec() .then(user =>{ user.posts = user.posts.filter(post => String(post._id) !== req.params.postId) + post.type === "request" ? user.requestCount = user.requestCount - 1 : user.donationCount = user.donationCount - 1 user.save() .then(response => { res.status(200).json({message : "Post deleted!",post}) diff --git a/api/controllers/signup.js b/api/controllers/signup.js index 25c8191..754d53d 100644 --- a/api/controllers/signup.js +++ b/api/controllers/signup.js @@ -92,6 +92,7 @@ exports.login = (req,res) => { }) return res.status(200).json({ message : "Logged in", + userId : user._id, username : user.username, email : user.email, isLoggedIn : true, diff --git a/api/routes/posts.js b/api/routes/posts.js index 1c5b3d2..019d83a 100644 --- a/api/routes/posts.js +++ b/api/routes/posts.js @@ -8,20 +8,48 @@ const PostController = require('../controllers/post'); //get all posts router.get('/api/posts',PostController.getAllPosts) + + // get a post +//reqs attributes +// postId router.get('/api/posts/:postId',PostController.getPost) //make a post +//req attributes +// avatar , +// title , +// author , +// type , +// status , +// description , +// items, +// location, +// tags, +// datePosted, +// deadline, +// photos , router.post('/api/posts',checkAuth,PostController.makePost); //make a comment -router.patch('/api/posts/:postId/comments',PostController.makeComment); - -//like/unlike a post -router.patch('/api/posts/:postId/likes',PostController.likePost); - -router.delete('/api/posts/:postId',PostController.deletePost); +// req attributes +// avatar +// username +// content +// postId +router.patch('/api/posts/:postId/comments',checkAuth,PostController.makeComment); + +// like/unlike a post +// req attributes +// userId +// postId +router.patch('/api/posts/:postId/likes',checkAuth,PostController.likePost); + +// delete a post +// req attributes +// postId +router.delete('/api/posts/:postId',checkAuth,PostController.deletePost); module.exports = router; \ No newline at end of file diff --git a/api/routes/signup.js b/api/routes/signup.js index 69de816..30a4b4c 100644 --- a/api/routes/signup.js +++ b/api/routes/signup.js @@ -10,11 +10,22 @@ const User = require('../models/user'); const { response } = require('express'); - +// signup +// req attributes: +// username +// password +// firstName +// lastName +// email +// location +// contactNumber router.post('/api/signup', Auth.signup) // login user +// req attributes: +// email +// password router.post('/api/login', Auth.login) module.exports = router; \ No newline at end of file diff --git a/api/routes/users.js b/api/routes/users.js index 44db2fd..ae4a2b5 100644 --- a/api/routes/users.js +++ b/api/routes/users.js @@ -10,11 +10,15 @@ router.get('/api/users',UserController.getAllUsers) // get one user +// req attributes: +// userId router.get('/api/users/:userId',UserController.getUser) // get all post liked by a user +// req attribute: +// userId router.get('/api/users/:userId/likedPosts',UserController.getLikedPosts) diff --git a/config/keys.js b/config/keys.js deleted file mode 100644 index df5702b..0000000 --- a/config/keys.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - mongoURI : "mongodb+srv://grouptwo:padthebest@donasource.8omhn.mongodb.net/?retryWrites=true&w=majority" -} \ No newline at end of file diff --git a/client/notes.txt b/notes.txt similarity index 100% rename from client/notes.txt rename to notes.txt