mirror of
https://github.com/bubblecup-12/VogelSocialMedia.git
synced 2025-07-07 04:28:46 +00:00
add follow function and make small style changes
This commit is contained in:
parent
79e1f4ebe0
commit
9a9724d024
8 changed files with 57 additions and 19 deletions
|
@ -202,6 +202,7 @@ export const updateBio = async (req: Request, res: Response) => {
|
|||
// Endpoint to get user data
|
||||
export const getProfile = async (req: Request, res: Response) => {
|
||||
const username: string = req.params.username as string;
|
||||
const requestingUser: JwtPayload | undefined = req.user;
|
||||
if (!username) {
|
||||
res.status(StatusCodes.BAD_REQUEST).json({
|
||||
error: "no username",
|
||||
|
@ -227,9 +228,22 @@ export const getProfile = async (req: Request, res: Response) => {
|
|||
|
||||
const publicUser: PublicUser | undefined = await getUser(user.id);
|
||||
|
||||
let isFollowing : boolean = false;
|
||||
if(requestingUser) {
|
||||
const followingData = await prisma.follow.findFirst({
|
||||
where: {
|
||||
followedUserId: user.id,
|
||||
followingUserId: requestingUser.id,
|
||||
}
|
||||
})
|
||||
if(followingData) {
|
||||
isFollowing = true;
|
||||
}
|
||||
}
|
||||
|
||||
res.status(StatusCodes.OK).json({
|
||||
message: "User found",
|
||||
data: publicUser,
|
||||
data: {...publicUser, isFollowing},
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
|
|
|
@ -10,6 +10,7 @@ const profileRouter = express.Router();
|
|||
import { upload } from "../middleware/uploadSingle";
|
||||
import { updateBioSchema } from "../schemas/profileSchemas";
|
||||
import { validateData } from "../middleware/validationMiddleware";
|
||||
import { optionalAuthenticateToken } from "../middleware/optionalAuthenticateToken";
|
||||
/**
|
||||
* @swagger
|
||||
* /api/profile/uploadProfilePicture:
|
||||
|
@ -124,5 +125,5 @@ profileRouter.put(
|
|||
* 401:
|
||||
* description: Ungültige Anmeldedaten
|
||||
*/
|
||||
profileRouter.get("/:username", getProfile);
|
||||
profileRouter.get("/:username", optionalAuthenticateToken, getProfile);
|
||||
export default profileRouter;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue