mirror of
https://github.com/beilunyang/moemail.git
synced 2026-09-05 07:16:39 +08:00
feat: Enhance role management by adding role assignment functionality and checks for existing roles
This commit is contained in:
@@ -17,13 +17,27 @@ export async function POST(request: Request) {
|
||||
|
||||
if (roleName !== ROLES.KNIGHT) {
|
||||
return Response.json(
|
||||
{ error: "角色不合法" },
|
||||
{ error: "只能册封骑士" },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const db = createDb();
|
||||
|
||||
const isEmperor = await db.query.userRoles.findFirst({
|
||||
where: eq(userRoles.userId, userId),
|
||||
with: {
|
||||
role: true,
|
||||
},
|
||||
}).then(userRole => userRole?.role.name === ROLES.EMPEROR);
|
||||
|
||||
if (isEmperor) {
|
||||
return Response.json(
|
||||
{ error: "不能降级皇帝" },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
let targetRole = await db.query.roles.findFirst({
|
||||
where: eq(roles.name, roleName),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user