20 lines
602 B
TypeScript
20 lines
602 B
TypeScript
|
|
import type { NextApiRequest, NextApiResponse } from 'next'
|
||
|
|
import { prisma } from '@/lib/prisma'
|
||
|
|
import { requireAuth } from '@/lib/auth'
|
||
|
|
|
||
|
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||
|
|
const user = await requireAuth(req, res, ['ADMIN', 'QC'])
|
||
|
|
if (!user) return
|
||
|
|
|
||
|
|
if (req.method === 'GET') {
|
||
|
|
const users = await prisma.user.findMany({
|
||
|
|
where: { active: true },
|
||
|
|
select: { id: true, name: true, email: true, role: true, department: true },
|
||
|
|
orderBy: { name: 'asc' },
|
||
|
|
})
|
||
|
|
return res.json({ data: users })
|
||
|
|
}
|
||
|
|
|
||
|
|
res.status(405).end()
|
||
|
|
}
|