tambahan
This commit is contained in:
51
src/server/routes/user_route.ts
Normal file
51
src/server/routes/user_route.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import Elysia, { t } from "elysia";
|
||||
import type { User } from "generated/prisma";
|
||||
import { prisma } from "../lib/prisma";
|
||||
|
||||
const UserRoute = new Elysia({
|
||||
prefix: "user",
|
||||
tags: ["user"],
|
||||
})
|
||||
.get('/find', (ctx) => {
|
||||
const { user } = ctx as any
|
||||
return {
|
||||
user: user as User
|
||||
}
|
||||
}, {
|
||||
detail: {
|
||||
summary: "find",
|
||||
description: "find user",
|
||||
}
|
||||
})
|
||||
.post("/upsert", async (ctx) => {
|
||||
const { name, phone } = ctx.body
|
||||
const upsert = await prisma.user.upsert({
|
||||
where: {
|
||||
phone
|
||||
},
|
||||
update: {
|
||||
name
|
||||
},
|
||||
create: {
|
||||
name,
|
||||
phone
|
||||
}
|
||||
})
|
||||
|
||||
return {
|
||||
success: true,
|
||||
upsert
|
||||
}
|
||||
|
||||
}, {
|
||||
body: t.Object({
|
||||
name: t.String({ minLength: 1, error: "name is required" }),
|
||||
phone: t.String({ minLength: 1, error: "phone is required" })
|
||||
}),
|
||||
detail: {
|
||||
summary: "upsert",
|
||||
description: "upsert user",
|
||||
}
|
||||
})
|
||||
|
||||
export default UserRoute
|
||||
Reference in New Issue
Block a user