adding picture display with cloudfront and working on ios take photo and post flow
This commit is contained in:
@@ -3,6 +3,21 @@ import Post from '../models/postModel.js'
|
||||
|
||||
export const getAllPosts = async (req, res, next) => {
|
||||
const allPosts = await Post.find({}).exec()
|
||||
allPosts.map((el) => {
|
||||
el.photo = process.env.CLOUDFRONT_URL + el.photo
|
||||
})
|
||||
res.status(200).json({
|
||||
status: 'success',
|
||||
data: allPosts
|
||||
})
|
||||
}
|
||||
|
||||
export const getAllPostsByStatus = async (req, res, next) => {
|
||||
console.log(req.params.status)
|
||||
const allPosts = await Post.find({ status: req.params.status }).exec()
|
||||
allPosts.map((el) => {
|
||||
el.photo = process.env.CLOUDFRONT_URL + el.photo
|
||||
})
|
||||
res.status(200).json({
|
||||
status: 'success',
|
||||
data: allPosts
|
||||
@@ -35,13 +50,14 @@ export const createPost = async (req, res, next) => {
|
||||
const aws = new AWSUtil()
|
||||
|
||||
// Grab base64 photo from the req body
|
||||
const location = await aws.uploadFile(req.body.photo)
|
||||
|
||||
const fileName = await aws.uploadFile(req.body.photo)
|
||||
const payload = {
|
||||
...req.body,
|
||||
photo: location
|
||||
photo: fileName
|
||||
}
|
||||
|
||||
console.log(payload)
|
||||
|
||||
Post.create(payload).then((result) => {
|
||||
res.status(200).json({
|
||||
status: 'success',
|
||||
|
||||
Reference in New Issue
Block a user