20 lines
522 B
TypeScript
20 lines
522 B
TypeScript
|
|
import { NextResponse } from 'next/server';
|
||
|
|
|
||
|
|
import { withAuth, withPermission } from '@/lib/api/helpers';
|
||
|
|
import { db } from '@/lib/db';
|
||
|
|
import { errorResponse } from '@/lib/errors';
|
||
|
|
|
||
|
|
export const GET = withAuth(
|
||
|
|
withPermission('admin', 'manage_users', async (_req, _ctx) => {
|
||
|
|
try {
|
||
|
|
const data = await db.query.roles.findMany({
|
||
|
|
orderBy: (roles, { asc }) => [asc(roles.name)],
|
||
|
|
});
|
||
|
|
|
||
|
|
return NextResponse.json({ data });
|
||
|
|
} catch (error) {
|
||
|
|
return errorResponse(error);
|
||
|
|
}
|
||
|
|
}),
|
||
|
|
);
|