mirror of
https://github.com/detleph/server.git
synced 2026-09-04 00:26:03 +02:00
Add a controller for getting all admin user details
+ Requires Authentication
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import prisma from "../lib/prisma";
|
||||
import { Request, Response } from "express";
|
||||
|
||||
// requires: auth(elevated)
|
||||
export const getAllAdmins = async (req: Request, res: Response) => {
|
||||
if (!req.auth?.isAuthenticated) {
|
||||
return res.status(500).json({
|
||||
type: "failure",
|
||||
payload: {
|
||||
message: "The server was not able to validate your credentials; Please try again later",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (req.auth.permission_level !== "ELEVATED") {
|
||||
return res.status(403).json({
|
||||
type: "error",
|
||||
payload: {
|
||||
message: "You do not have sufficient permissions to use this feature",
|
||||
},
|
||||
_links: [
|
||||
{
|
||||
rel: "authentication",
|
||||
href: "/api/authentication",
|
||||
type: "POST",
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: Add exception handling
|
||||
const users = await prisma.admin.findMany({ select: { pid: true, name: true, permission_level: true } });
|
||||
|
||||
res.status(200).json({
|
||||
type: "success",
|
||||
payload: {
|
||||
users,
|
||||
},
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user