API & UI Menu Inovasi, SubMenu Layanan Online Desa
This commit is contained in:
30
src/app/api/[[...slugs]]/_lib/desa/berita/findFirst.ts
Normal file
30
src/app/api/[[...slugs]]/_lib/desa/berita/findFirst.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import prisma from '@/lib/prisma';
|
||||
|
||||
export default async function beritaFindFirst() {
|
||||
try {
|
||||
const result = await prisma.berita.findFirst({
|
||||
where: {
|
||||
isActive: true, // opsional kalau kamu punya field ini
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: 'desc', // ambil yang paling terbaru
|
||||
},
|
||||
include: {
|
||||
image: true,
|
||||
kategoriBerita: true,
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: 'Berhasil ambil berita terbaru',
|
||||
data: result,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('[findFirstBerita] Error:', error);
|
||||
return {
|
||||
success: false,
|
||||
message: 'Gagal ambil berita terbaru',
|
||||
};
|
||||
}
|
||||
}
|
||||
19
src/app/api/[[...slugs]]/_lib/desa/berita/findRecent.ts
Normal file
19
src/app/api/[[...slugs]]/_lib/desa/berita/findRecent.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
|
||||
export default async function findRecentBerita() {
|
||||
const result = await prisma.berita.findMany({
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
take: 4, // ambil 4 data terbaru
|
||||
include: {
|
||||
image: true,
|
||||
kategoriBerita: true,
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: result,
|
||||
};
|
||||
}
|
||||
@@ -5,6 +5,8 @@ import beritaCreate from "./create";
|
||||
import beritaDelete from "./del";
|
||||
import beritaUpdate from "./updt";
|
||||
import findBeritaById from "./find-by-id";
|
||||
import beritaFindFirst from "./findFirst";
|
||||
import findRecentBerita from "./findRecent";
|
||||
|
||||
const Berita = new Elysia({ prefix: "/berita", tags: ["Desa/Berita"] })
|
||||
.get("/category/find-many", kategoriBeritaFindMany)
|
||||
@@ -22,6 +24,8 @@ const Berita = new Elysia({ prefix: "/berita", tags: ["Desa/Berita"] })
|
||||
kategoriBeritaId: t.Union([t.String(), t.Null()]),
|
||||
}),
|
||||
})
|
||||
.get("/find-first", beritaFindFirst)
|
||||
.get("/find-recent", findRecentBerita)
|
||||
.delete("/delete/:id", beritaDelete)
|
||||
.put(
|
||||
"/:id",
|
||||
@@ -39,5 +43,6 @@ const Berita = new Elysia({ prefix: "/berita", tags: ["Desa/Berita"] })
|
||||
}),
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
export default Berita;
|
||||
|
||||
29
src/app/api/[[...slugs]]/_lib/desa/pengumuman/findFirst.ts
Normal file
29
src/app/api/[[...slugs]]/_lib/desa/pengumuman/findFirst.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import prisma from '@/lib/prisma';
|
||||
|
||||
export default async function pengumumanFindFirst() {
|
||||
try {
|
||||
const result = await prisma.pengumuman.findFirst({
|
||||
where: {
|
||||
isActive: true, // opsional kalau kamu punya field ini
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: 'desc', // ambil yang paling terbaru
|
||||
},
|
||||
include: {
|
||||
CategoryPengumuman: true,
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: 'Berhasil ambil pengumuman terbaru',
|
||||
data: result,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('[findFirstPengumuman] Error:', error);
|
||||
return {
|
||||
success: false,
|
||||
message: 'Gagal ambil pengumuman terbaru',
|
||||
};
|
||||
}
|
||||
}
|
||||
18
src/app/api/[[...slugs]]/_lib/desa/pengumuman/findRecent.ts
Normal file
18
src/app/api/[[...slugs]]/_lib/desa/pengumuman/findRecent.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
|
||||
export default async function pengumumanFindRecent() {
|
||||
const result = await prisma.pengumuman.findMany({
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
take: 4, // ambil 4 data terbaru
|
||||
include: {
|
||||
CategoryPengumuman: true,
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: result,
|
||||
};
|
||||
}
|
||||
@@ -6,6 +6,8 @@ import pengumumanCategoryFindMany from "./category";
|
||||
import pengumumanDelete from "./del";
|
||||
import pengumumanFindById from "./find-by-id";
|
||||
import pengumumanUpdate from "./updt";
|
||||
import pengumumanFindFirst from "./findFirst";
|
||||
import pengumumanFindRecent from "./findRecent";
|
||||
|
||||
const Pengumuman = new Elysia({ prefix: "/pengumuman", tags: ["Desa/Pengumuman"] })
|
||||
.get("/category/find-many", pengumumanCategoryFindMany)
|
||||
@@ -20,6 +22,8 @@ const Pengumuman = new Elysia({ prefix: "/pengumuman", tags: ["Desa/Pengumuman"]
|
||||
categoryPengumumanId: t.Union([t.String(), t.Null()]),
|
||||
}),
|
||||
})
|
||||
.get("/find-first", pengumumanFindFirst)
|
||||
.get("/find-recent", pengumumanFindRecent)
|
||||
.put("/:id", pengumumanUpdate, {
|
||||
body: t.Object({
|
||||
id: t.String(),
|
||||
|
||||
Reference in New Issue
Block a user