2021-12-19 20:03:59 -03:00
|
|
|
import { prisma } from 'services/prisma'
|
|
|
|
|
import { ExceptionError } from 'utils/error'
|
2021-12-18 22:41:05 -03:00
|
|
|
|
2021-12-23 14:51:34 -03:00
|
|
|
import type { NextApiRequest, NextApiResponse } from 'next'
|
|
|
|
|
|
|
|
|
|
export async function getUserById(req: NextApiRequest, res: NextApiResponse) {
|
|
|
|
|
const { id } = req.params
|
|
|
|
|
|
2021-12-19 20:03:59 -03:00
|
|
|
const response = await prisma.user.findUnique({
|
2021-12-23 14:51:34 -03:00
|
|
|
where: { id: +id },
|
2021-12-19 20:03:59 -03:00
|
|
|
select: {
|
|
|
|
|
id: true,
|
|
|
|
|
username: true,
|
|
|
|
|
role: true
|
2021-12-18 22:41:05 -03:00
|
|
|
}
|
2021-12-19 20:03:59 -03:00
|
|
|
})
|
2021-12-18 22:41:05 -03:00
|
|
|
|
2021-12-19 20:03:59 -03:00
|
|
|
if (!response) {
|
2021-12-23 14:51:34 -03:00
|
|
|
throw new ExceptionError('No data found', 404)
|
2021-12-19 20:03:59 -03:00
|
|
|
}
|
2021-12-18 22:41:05 -03:00
|
|
|
|
2021-12-19 20:03:59 -03:00
|
|
|
res.status(200).json(response)
|
2021-12-23 14:51:34 -03:00
|
|
|
}
|