feat(/server/api/user/create): Add User to db

This commit is contained in:
漩葵 2024-06-18 23:54:20 +08:00
parent 02d8b6d5a6
commit f91f2728d6
3 changed files with 19 additions and 1 deletions

View File

@ -12,7 +12,7 @@
>
<ClientOnly>
<Vueform
endpoint="/api/test"
endpoint="/api/user/create"
method="POST"
view="tabs"
:model-value="form"

View File

@ -10,6 +10,8 @@ export default defineEventHandler(async (event) => {
deadline: "desc", // 'asc' 表示升序,'desc' 表示降序
},
})) || {
phone: "",
code: "",
deadline: new Date(),
};
const deadlineDate = new Date(register.deadline);

16
server/api/user/create.ts Normal file
View File

@ -0,0 +1,16 @@
import { PrismaClient } from "@prisma/client";
const db = new PrismaClient();
export default defineEventHandler(async (event) => {
const body = await readBody(event);
await db.user.create({
data: {
username: body.username,
phone: body.phone,
password: (await import("crypto"))
.createHash("md5")
.update(body.password)
.digest("hex"),
},
});
return 1;
});