Bagian Berita Di Admin Sudah Bisa Upload Di Bun Dev atau Bun Start
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
|
||||
async function katagoryBeritaFindMany() {
|
||||
const data = await prisma.katagoryBerita.findMany();
|
||||
async function kategoriBeritaFindMany() {
|
||||
const data = await prisma.kategoriBerita.findMany();
|
||||
return { data };
|
||||
}
|
||||
|
||||
export default katagoryBeritaFindMany
|
||||
export default kategoriBeritaFindMany
|
||||
|
||||
|
||||
@@ -6,13 +6,14 @@ type FormCreate = Prisma.BeritaGetPayload<{
|
||||
select: {
|
||||
judul: true;
|
||||
deskripsi: true;
|
||||
image: true;
|
||||
content: true;
|
||||
katagoryBeritaId: true;
|
||||
kategoriBeritaId: true;
|
||||
imageId: true;
|
||||
};
|
||||
}>;
|
||||
async function beritaCreate(context: Context) {
|
||||
const body = context.body as FormCreate;
|
||||
console.log(body)
|
||||
|
||||
// console.log(body)
|
||||
|
||||
@@ -20,9 +21,9 @@ async function beritaCreate(context: Context) {
|
||||
data: {
|
||||
content: body.content,
|
||||
deskripsi: body.deskripsi,
|
||||
image: body.image,
|
||||
imageId: body.imageId,
|
||||
judul: body.judul,
|
||||
katagoryBeritaId: body.katagoryBeritaId,
|
||||
kategoriBeritaId: body.kategoriBeritaId,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -1,8 +1,27 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
|
||||
export default async function beritaFindMany() {
|
||||
const res = await prisma.berita.findMany();
|
||||
return {
|
||||
data: res,
|
||||
};
|
||||
async function beritaFindMany() {
|
||||
try {
|
||||
const data = await prisma.berita.findMany({
|
||||
where: { isActive: true },
|
||||
include: {
|
||||
image: true,
|
||||
kategoriBerita: true,
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Success fetch berita",
|
||||
data,
|
||||
};
|
||||
} catch (e) {
|
||||
console.error("Find many error:", e);
|
||||
return {
|
||||
success: false,
|
||||
message: "Failed fetch berita",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default beritaFindMany;
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
import Elysia, { t } from "elysia";
|
||||
import katagoryBeritaFindMany from "./category";
|
||||
import kategoriBeritaFindMany from "./category";
|
||||
import beritaFindMany from "./find-many";
|
||||
import beritaCreate from "./create";
|
||||
|
||||
const Berita = new Elysia({ prefix: "/berita", tags: ["Desa/Berita"] })
|
||||
.get("/category/find-many", katagoryBeritaFindMany)
|
||||
.get("/category/find-many", kategoriBeritaFindMany)
|
||||
.get("/find-many", beritaFindMany)
|
||||
.post("/create", beritaCreate, {
|
||||
body: t.Object({
|
||||
judul: t.String(),
|
||||
deskripsi: t.String(),
|
||||
image: t.String(),
|
||||
imageId: t.String(),
|
||||
content: t.String(),
|
||||
katagoryBeritaId: t.Union([t.String(), t.Null()]),
|
||||
kategoriBeritaId: t.Union([t.String(), t.Null()]),
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user