Skip to content

Commit

Permalink
Merge pull request #31 from millionhz/jazlan-img
Browse files Browse the repository at this point in the history
upload Image post
  • Loading branch information
millionhz authored Nov 30, 2022
2 parents 2c19fcb + a38c8b5 commit e3d3883
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions server/routes/api/image-j.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// create a query to insert an image
const storeImage_J = (post_id, image_content) => {
const modifiedTime = getCurrentTime();
const sql = `INSERT INTO images (binary, created_time) VALUES (?, ?)`

return query(sql, [image_content, modifiedTime]).then(()=> {
const id_query = `SELECT image_id FROM images where image_id = (SELECT LAST_INSERT_ID());`
var id = query(id_query)
id = id["image_id"]

// update image table now
const posts_table = `UPDATE posts SET (image_id = ?) WHERE post_id = ?;`
return query(posts_table, [id, post_id])

})
};

Routes
router.get('/:postId/image_J', (req, res, next) => {
const { image } = req.params;
const { postId } = req.params;

storeImage_J(postId, image)
.then(() => {

res.sendStatus(200);
})
.catch((err) => {

res.status(500).json({ message: err.message });
next(err);
});
});

0 comments on commit e3d3883

Please sign in to comment.