Add a controller for getting all admin user details

+ Requires Authentication
This commit is contained in:
Stephan
2022-04-28 12:49:07 +02:00
committed by Stefan-5422
parent 5e5b6bb60c
commit fdfbd22daf
+40
View File
@@ -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,
},
});
};