mirror of
https://github.com/dsoaress/link-free.git
synced 2026-08-17 06:56:04 +01:00
feat: add user management section
This commit is contained in:
23
src/api/users/getUserById.ts
Normal file
23
src/api/users/getUserById.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { prisma } from 'services/prisma'
|
||||
import { ExceptionError } from 'utils/error'
|
||||
|
||||
import type { NextApiRequest, NextApiResponse } from 'next'
|
||||
|
||||
export async function getUserById(req: NextApiRequest, res: NextApiResponse) {
|
||||
const { id } = req.params
|
||||
|
||||
const response = await prisma.user.findUnique({
|
||||
where: { id: +id },
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
role: true
|
||||
}
|
||||
})
|
||||
|
||||
if (!response) {
|
||||
throw new ExceptionError('No data found', 404)
|
||||
}
|
||||
|
||||
res.status(200).json(response)
|
||||
}
|
||||
Reference in New Issue
Block a user