60 lines
1.3 KiB
TypeScript
60 lines
1.3 KiB
TypeScript
import Elysia, { t } from "elysia";
|
|
import { prisma } from "../lib/prisma";
|
|
|
|
const CredentialRoute = new Elysia({
|
|
prefix: "/credential",
|
|
tags: ["credential"],
|
|
})
|
|
.post("/create", async (ctx) => {
|
|
const { name, value } = ctx.body
|
|
const create = await prisma.credential.create({
|
|
data: {
|
|
name,
|
|
value
|
|
}
|
|
})
|
|
return {
|
|
message: "success",
|
|
create
|
|
}
|
|
}, {
|
|
body: t.Object({
|
|
name: t.String(),
|
|
value: t.String(),
|
|
}),
|
|
detail: {
|
|
summary: 'create',
|
|
description: 'create credential',
|
|
}
|
|
})
|
|
.get("/list", async () => {
|
|
const list = await prisma.credential.findMany()
|
|
return {
|
|
message: "success",
|
|
list
|
|
}
|
|
}, {
|
|
detail: {
|
|
summary: 'list',
|
|
description: 'get credential list',
|
|
}
|
|
})
|
|
.delete("/rm", async (ctx) => {
|
|
const { id } = ctx.body
|
|
await prisma.credential.delete({
|
|
where: {
|
|
id: id
|
|
}
|
|
})
|
|
|
|
}, {
|
|
body: t.Object({
|
|
id: t.String()
|
|
}),
|
|
detail: {
|
|
summary: 'rm',
|
|
description: 'delete credential by id',
|
|
}
|
|
})
|
|
|
|
export default CredentialRoute |