mirror of
https://github.com/massbug/judge4c.git
synced 2025-07-07 10:10:51 +00:00
- 为 adminActions、guestActions、problemActions 和 teacherActions 文件中的函数添加了明确的类型注解 - 更新了函数参数和返回值的类型,提高了代码的可读性和可维护性 - 在相关页面组件中添加了类型注解,明确了数据结构 - 移除了未使用的 Separator 组件导入
24 lines
837 B
TypeScript
24 lines
837 B
TypeScript
'use server'
|
|
import prisma from '@/lib/prisma'
|
|
import { revalidatePath } from 'next/cache'
|
|
import bcrypt from 'bcryptjs'
|
|
import type { User } from '@/generated/client'
|
|
|
|
export async function createGuest(data: Omit<User, 'id'|'createdAt'|'updatedAt'> & { password?: string }) {
|
|
let password = data.password
|
|
if (password) {
|
|
password = await bcrypt.hash(password, 10)
|
|
}
|
|
await prisma.user.create({ data: { ...data, password, role: 'GUEST' } })
|
|
revalidatePath('/usermanagement/guest')
|
|
}
|
|
|
|
export async function updateGuest(id: string, data: Partial<Omit<User, 'id'|'createdAt'|'updatedAt'>>) {
|
|
await prisma.user.update({ where: { id }, data })
|
|
revalidatePath('/usermanagement/guest')
|
|
}
|
|
|
|
export async function deleteGuest(id: string) {
|
|
await prisma.user.delete({ where: { id } })
|
|
revalidatePath('/usermanagement/guest')
|
|
}
|