reorg to domain and api

This commit is contained in:
Alex Holliday committed 2026-06-09 12:34:15 -07:00
1 parent 0fb210e9e1
commit d022f7d849
190 files changed
+643 -830

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
import type { Request, Response, NextFunction } from "express";
const SERVICE_NAME = "allowedRoles";
import { AppError } from "@/utils/AppError.js";
import type { UserRole } from "@/domain/users/user.type.js";
const isAllowed = (allowedRoles: UserRole[]) => {
return (req: Request, res: Response, next: NextFunction) => {
try {
const user = req.user;
if (!user) {
throw new AppError({ message: "Unauthorized", status: 403, service: SERVICE_NAME });
}
const userRoles = req.user?.role || [];
// Check if the user has the required role
if (userRoles.some((role) => allowedRoles.includes(role))) {
next();
return;
} else {
throw new AppError({ message: "Unauthorized", status: 403, service: SERVICE_NAME });
}
} catch (error) {
next(error);
return;
}
};
};
export { isAllowed };