Membuat database menu desa: Berita & Pengummuman
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
|
||||
async function pengumumanCategoryFindMany() {
|
||||
const data = await prisma.categoryPengumuman.findMany();
|
||||
return { data };
|
||||
}
|
||||
|
||||
export default pengumumanCategoryFindMany
|
||||
43
src/app/api/[[...slugs]]/_lib/desa/pengumuman/create.ts
Normal file
43
src/app/api/[[...slugs]]/_lib/desa/pengumuman/create.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { Context } from "elysia";
|
||||
|
||||
type FormCreate = Prisma.PengumumanGetPayload<{
|
||||
select: {
|
||||
judul: true;
|
||||
deskripsi: true;
|
||||
content: true;
|
||||
categoryPengumumanId: true;
|
||||
};
|
||||
}>;
|
||||
|
||||
export async function pengumumanCreate(context: Context) {
|
||||
const body = context.body as FormCreate;
|
||||
|
||||
try {
|
||||
await prisma.pengumuman.create({
|
||||
data: {
|
||||
content: body.content,
|
||||
deskripsi: body.deskripsi,
|
||||
judul: body.judul,
|
||||
categoryPengumumanId: body.categoryPengumumanId,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
console.error(body)
|
||||
return {
|
||||
success: false,
|
||||
message: "Failed create pengumuman",
|
||||
error: error,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Success create pengumuman",
|
||||
data: {
|
||||
...body,
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
|
||||
export default async function pengumumanFindMany() {
|
||||
const res = await prisma.pengumuman.findMany();
|
||||
return {
|
||||
data: res,
|
||||
};
|
||||
}
|
||||
19
src/app/api/[[...slugs]]/_lib/desa/pengumuman/index.ts
Normal file
19
src/app/api/[[...slugs]]/_lib/desa/pengumuman/index.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import Elysia from "elysia";
|
||||
import { pengumumanCreate } from "./create";
|
||||
import pengumumanFindMany from "./find-many";
|
||||
import { t } from "elysia";
|
||||
import pengumumanCategoryFindMany from "./category";
|
||||
|
||||
const Pengumuman = new Elysia({ prefix: "/pengumuman", tags: ["Desa/Pengumuman"] })
|
||||
.get("/category/find-many", pengumumanCategoryFindMany)
|
||||
.get("/find-many", pengumumanFindMany)
|
||||
.post("/create", pengumumanCreate, {
|
||||
body: t.Object({
|
||||
judul: t.String(),
|
||||
deskripsi: t.String(),
|
||||
content: t.String(),
|
||||
categoryPengumumanId: t.Union([t.String(), t.Null()]),
|
||||
}),
|
||||
});
|
||||
|
||||
export default Pengumuman;
|
||||
Reference in New Issue
Block a user