Skip to content

Commit

Permalink
✨ [FEAT]: post 수정 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
eunji8784 committed Dec 24, 2021
1 parent e4471d2 commit 83013d4
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions 5st-seminar/functions/api/routes/post/postPUT.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const functions = require("firebase-functions");
const util = require("../../../lib/util");
const statusCode = require("../../../constants/statusCode");
const responseMessage = require("../../../constants/responseMessage");
const db = require("../../../db/db");
const { postDB } = require("../../../db");

module.exports = async (req, res) => {
const { postId } = req.params;
const { title, content } = req.body;

if (!postId)
return res
.status(statusCode.BAD_REQUEST)
.send(util.fail(statusCode.BAD_REQUEST, responseMessage.NULL_VALUE));

let client;

try {
client = await db.connect(req);
const updatedPost = await postDB.updatePost(client, title, content, postId);
if (!updatedPost)
return res
.status(statusCode.NOT_FOUND)
.send(util.fail(statusCode.NOT_FOUND, responseMessage.NO_POST));

res
.status(statusCode.OK)
.send(
util.success(
statusCode.OK,
responseMessage.UPDATE_ONE_POST_SUCCESS,
updatedPost
)
);
} catch (error) {
functions.logger.error(
`[ERROR] [${req.method.toUpperCase()}] ${req.originalUrl}`,
`[CONTENT] ${error}`
);
console.log(error);

res
.status(statusCode.INTERNAL_SERVER_ERROR)
.send(
util.fail(
statusCode.INTERNAL_SERVER_ERROR,
responseMessage.INTERNAL_SERVER_ERROR
)
);
} finally {
client.release();
}
};

0 comments on commit 83013d4

Please sign in to comment.