Skip to content

Commit

Permalink
Added endpoint for user id fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
OzPol authored Jul 1, 2024
1 parent 2437128 commit 6d67ff0
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions pages/api/profile/[id].ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// [id].ts: [] in file names for dynamic routes in Next.js
// This endpoint is part of the user profile management feature
// it fetches a user's profile by their ID.
// pages/api/profile/[id].ts
// pages/api/profile/[id].ts
import { NextApiRequest, NextApiResponse } from 'next';
import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

const getProfile = async (req: NextApiRequest, res: NextApiResponse) => {
const { id } = req.query;

try {
const user = await prisma.user.findUnique({
where: { id: Number(id) },
});

if (user) {
res.status(200).json(user);
} else {
res.status(404).json({ message: 'User not found' });
}
} catch (error) {
res.status(500).json({ message: 'Internal server error', error });
}
};

export default getProfile;

0 comments on commit 6d67ff0

Please sign in to comment.