diff --git a/prisma/schema.prisma b/prisma/schema.prisma index ed33b53..b2dd327 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -24,6 +24,7 @@ model User { enum Role { USER ADMIN + CREATOR } model Post { diff --git a/src/api/users/roles.ts b/src/api/users/roles.ts index 7fd25fe..476134d 100644 --- a/src/api/users/roles.ts +++ b/src/api/users/roles.ts @@ -4,7 +4,7 @@ import { changeUserRoles, getUserById } from "@/controller/UserController"; export default async (req: Request, res: Response) => { try { const user = await getUserById(req.userId); - if (user?.role !== "ADMIN") { + if (user?.role !== "ADMIN" && user?.role !== "CREATOR") { return res.status(403).send({ error: "Forbidden" }); } const id = parseInt(req.params.id); diff --git a/src/controller/UserController.ts b/src/controller/UserController.ts index 43344d6..0c9f795 100644 --- a/src/controller/UserController.ts +++ b/src/controller/UserController.ts @@ -62,6 +62,9 @@ const newUser = async (user: User) => { }; export const changeUserRoles = async (id: number, role: Role) => { + if (role === 'CREATOR') { + return new Error('You cannot change user role to CREATOR'); + } const currentUser = await prisma.user.findUnique({ where: { id, @@ -74,6 +77,9 @@ export const changeUserRoles = async (id: number, role: Role) => { if (currentUser.role === role) { throw new Error('User already has this role'); } + if (currentUser.role === 'CREATOR') { + throw new Error('You cannot change role of user with CREATOR role'); + } const updatedUser = await prisma.user.update({ where: {