Skip to content

Commit

Permalink
Edit profile endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennull committed Apr 21, 2024
1 parent d35c80c commit 1d87553
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
17 changes: 17 additions & 0 deletions controllers/ProfileController.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
const pool = require("../database/db");
const profileQueries = require("../models/ProfileModel");

const editProfile = async (req, res) => {
try {
const { displayName, birthDate, bio, userId } = req.body;
const query = await pool.query(profileQueries.editProfile, [
displayName,
birthDate,
bio,
userId,
]);
res.send(query.rows[0]);
} catch (error) {
console.log(error);
res.status(500).send(error);
}
};

const getUserPosts = async (req, res) => {
try {
const { username } = req.query;
Expand Down Expand Up @@ -48,6 +64,7 @@ const getProfileContents = async (req, res) => {
};

module.exports = {
editProfile,
getUserPosts,
getUserReplies,
getUserLikes,
Expand Down
6 changes: 6 additions & 0 deletions models/ProfileModel.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
const editProfile = `
UPDATE app_user
SET "displayName" = $1, "birthDate" = $2, "bio" = $3
WHERE "userId" = $4`;

const getUserPosts = `
WITH post_likes AS (
SELECT "postId",
Expand Down Expand Up @@ -142,6 +147,7 @@ const getProfileContents = `
WHERE a."username" = $1`;

module.exports = {
editProfile,
getUserPosts,
getUserReplies,
getUserLikes,
Expand Down
3 changes: 2 additions & 1 deletion routes/profileRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ const profileController = require("../controllers/ProfileController");

const router = Router();

router.put("/", profileController.editProfile);
router.get("/getProfileContents", profileController.getProfileContents);
router.get("/getUserPosts", profileController.getUserPosts);
router.get("/getUserReplies", profileController.getUserReplies);
router.get("/getUserLikes", profileController.getUserLikes);
router.get("/getProfileContents", profileController.getProfileContents);

module.exports = router;

0 comments on commit 1d87553

Please sign in to comment.