adding pretteir and fixing post call so now clicking continue will upload to aws
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import AWSUtil from '../bin/aws.js';
|
||||
import Post from '../models/postModel.js';
|
||||
import AWSUtil from '../bin/aws.js'
|
||||
import Post from '../models/postModel.js'
|
||||
|
||||
export const getAllPosts = async (req, res, next) => {
|
||||
const allPosts = await Post.find({}).exec();
|
||||
const allPosts = await Post.find({}).exec()
|
||||
res.status(200).json({
|
||||
status: 'success',
|
||||
data: allPosts
|
||||
@@ -10,61 +10,60 @@ export const getAllPosts = async (req, res, next) => {
|
||||
}
|
||||
|
||||
export const getPost = async (req, res, next) => {
|
||||
const post = await Post.findById(req.params.id).exec();
|
||||
const post = await Post.findById(req.params.id).exec()
|
||||
if (!post) {
|
||||
return next('No document found with that id', 404);
|
||||
return next('No document found with that id', 404)
|
||||
}
|
||||
res.status(200).json({
|
||||
status: 'success',
|
||||
data: post
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
export const getAllPostsByUser = async (req, res, next) => {
|
||||
const post = await Post.find({email: req.params.user}).exec();
|
||||
const post = await Post.find({ email: req.params.user }).exec()
|
||||
if (!post) {
|
||||
return next('No document found with that id', 404);
|
||||
return next('No document found with that id', 404)
|
||||
}
|
||||
res.status(200).json({
|
||||
status: 'success',
|
||||
data: post
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
export const createPost = async (req, res, next) => {
|
||||
const aws = new AWSUtil();
|
||||
const aws = new AWSUtil()
|
||||
|
||||
// Grab base64 photo from the req body
|
||||
const location = await aws.uploadFile(req.body.photo);
|
||||
const location = await aws.uploadFile(req.body.photo)
|
||||
|
||||
const payload = {
|
||||
...req.body,
|
||||
photo: location
|
||||
}
|
||||
|
||||
|
||||
Post.create(payload).then(result => {
|
||||
Post.create(payload).then((result) => {
|
||||
res.status(200).json({
|
||||
status: 'success',
|
||||
data: result
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export const updatePost = async (req, res, next) => {
|
||||
Post.updateOne({_id: req.params.id},{$set: req.body}).then(result => {
|
||||
Post.updateOne({ _id: req.params.id }, { $set: req.body }).then((result) => {
|
||||
res.status(200).json({
|
||||
status: 'success',
|
||||
data: result
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export const deletePost = async (req, res, next) => {
|
||||
Post.deleteOne({_id: req.params.id}).then(result => {
|
||||
Post.deleteOne({ _id: req.params.id }).then((result) => {
|
||||
res.status(200).json({
|
||||
status: 'success',
|
||||
data: result
|
||||
});
|
||||
});
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user