feat(/server/api/user/create): Add User to db
This commit is contained in:
parent
02d8b6d5a6
commit
f91f2728d6
@ -12,7 +12,7 @@
|
||||
>
|
||||
<ClientOnly>
|
||||
<Vueform
|
||||
endpoint="/api/test"
|
||||
endpoint="/api/user/create"
|
||||
method="POST"
|
||||
view="tabs"
|
||||
:model-value="form"
|
||||
|
@ -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
16
server/api/user/create.ts
Normal 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;
|
||||
});
|
Loading…
Reference in New Issue
Block a user