2021-12-19 20:03:59 -03:00
|
|
|
import { prisma } from 'services/prisma'
|
|
|
|
|
import { authMiddleware } from 'utils/authMiddleware'
|
|
|
|
|
import { ExceptionError } from 'utils/error'
|
|
|
|
|
import { nc } from 'utils/nc'
|
2021-12-18 22:41:05 -03:00
|
|
|
|
2021-12-19 20:03:59 -03:00
|
|
|
const handler = nc.use(authMiddleware).get(async (req, res) => {
|
|
|
|
|
const { userId } = req
|
|
|
|
|
const response = await prisma.user.findUnique({
|
|
|
|
|
where: { id: +userId },
|
|
|
|
|
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) {
|
|
|
|
|
throw new ExceptionError('User not found')
|
|
|
|
|
}
|
2021-12-18 22:41:05 -03:00
|
|
|
|
2021-12-19 20:03:59 -03:00
|
|
|
res.status(200).json(response)
|
|
|
|
|
})
|
2021-12-18 22:41:05 -03:00
|
|
|
|
|
|
|
|
export default handler
|