Sinkronisasi Admin dan User, Menu Landing Page, Submenu Potensi
This commit is contained in:
@@ -7,6 +7,7 @@ import GalleryFoto from "./gallery/foto";
|
||||
import GalleryVideo from "./gallery/video";
|
||||
import LayananDesa from "./layanan";
|
||||
import Penghargaan from "./penghargaan";
|
||||
import KategoriPotensi from "./potensi/kategori-potensi";
|
||||
|
||||
|
||||
const Desa = new Elysia({ prefix: "/api/desa", tags: ["Desa"] })
|
||||
@@ -18,5 +19,6 @@ const Desa = new Elysia({ prefix: "/api/desa", tags: ["Desa"] })
|
||||
.use(GalleryVideo)
|
||||
.use(LayananDesa)
|
||||
.use(Penghargaan)
|
||||
.use(KategoriPotensi)
|
||||
|
||||
export default Desa;
|
||||
|
||||
@@ -1,21 +1,43 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
|
||||
export default async function pelayananTelunjukSaktiDesaFindMany() {
|
||||
export default async function pelayananTelunjukSaktiDesaFindMany(context: Context) {
|
||||
const page = Number(context.query.page) || 1;
|
||||
const limit = Number(context.query.limit) || 10;
|
||||
const skip = (page - 1) * limit;
|
||||
|
||||
try {
|
||||
const data = await prisma.pelayananTelunjukSaktiDesa.findMany({
|
||||
where: { isActive: true },
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Success fetch pelayanan telunjuk sakti desa",
|
||||
data,
|
||||
};
|
||||
const [data, total] = await Promise.all([
|
||||
prisma.pelayananTelunjukSaktiDesa.findMany({
|
||||
where: { isActive: true },
|
||||
skip,
|
||||
take: limit,
|
||||
orderBy: { createdAt: 'desc' },
|
||||
}),
|
||||
prisma.pelayananTelunjukSaktiDesa.count({
|
||||
where: { isActive: true }
|
||||
})
|
||||
]);
|
||||
|
||||
const totalPages = Math.ceil(total / limit);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Success fetch pelayanan telunjuk sakti desa with pagination",
|
||||
data,
|
||||
page,
|
||||
totalPages,
|
||||
total,
|
||||
};
|
||||
} catch (e) {
|
||||
console.error("Find many error:", e);
|
||||
return {
|
||||
success: false,
|
||||
message: "Failed fetch pelayanan telunjuk sakti desa",
|
||||
};
|
||||
console.error("Find many paginated error:", e);
|
||||
return {
|
||||
success: false,
|
||||
message: "Failed fetch pelayanan telunjuk sakti desa with pagination",
|
||||
data: [],
|
||||
page: 1,
|
||||
totalPages: 1,
|
||||
total: 0,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ type FormCreate = Prisma.PotensiDesaGetPayload<{
|
||||
select: {
|
||||
name: true;
|
||||
deskripsi: true;
|
||||
kategori: true;
|
||||
kategoriId: true;
|
||||
imageId: true;
|
||||
content: true;
|
||||
}
|
||||
@@ -18,7 +18,7 @@ export default async function potensiDesaCreate(context: Context) {
|
||||
data: {
|
||||
name: body.name,
|
||||
deskripsi: body.deskripsi,
|
||||
kategori: body.kategori,
|
||||
kategoriId: body.kategoriId,
|
||||
imageId: body.imageId,
|
||||
content: body.content,
|
||||
},
|
||||
|
||||
@@ -17,6 +17,7 @@ const potensiDesaDelete = async (context: Context) => {
|
||||
where: { id },
|
||||
include: {
|
||||
image: true,
|
||||
kategori: true
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -1,26 +1,47 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
|
||||
async function potensiDesaFindMany() {
|
||||
export default async function potensiDesaFindMany(context: Context) {
|
||||
const page = Number(context.query.page) || 1;
|
||||
const limit = Number(context.query.limit) || 10;
|
||||
const skip = (page - 1) * limit;
|
||||
|
||||
try {
|
||||
const data = await prisma.potensiDesa.findMany({
|
||||
where: { isActive: true },
|
||||
include: {
|
||||
image: true,
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Success fetch potensi desa",
|
||||
data,
|
||||
};
|
||||
const [data, total] = await Promise.all([
|
||||
prisma.potensiDesa.findMany({
|
||||
where: { isActive: true },
|
||||
skip,
|
||||
take: limit,
|
||||
include: {
|
||||
image: true,
|
||||
kategori: true
|
||||
},
|
||||
orderBy: { createdAt: 'desc' },
|
||||
}),
|
||||
prisma.potensiDesa.count({
|
||||
where: { isActive: true }
|
||||
})
|
||||
]);
|
||||
|
||||
const totalPages = Math.ceil(total / limit);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Success fetch potensi desa with pagination",
|
||||
data,
|
||||
page,
|
||||
totalPages,
|
||||
total,
|
||||
};
|
||||
} catch (e) {
|
||||
console.error("Find many error:", e);
|
||||
return {
|
||||
success: false,
|
||||
message: "Failed fetch potensi desa",
|
||||
};
|
||||
console.error("Find many paginated error:", e);
|
||||
return {
|
||||
success: false,
|
||||
message: "Failed fetch potensi desa with pagination",
|
||||
data: [],
|
||||
page: 1,
|
||||
totalPages: 1,
|
||||
total: 0,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default potensiDesaFindMany
|
||||
}
|
||||
@@ -25,6 +25,7 @@ export default async function findUnique(
|
||||
where: { id },
|
||||
include: {
|
||||
image: true,
|
||||
kategori: true
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ const PotensiDesa = new Elysia({
|
||||
body: t.Object({
|
||||
name: t.String(),
|
||||
deskripsi: t.String(),
|
||||
kategori: t.String(),
|
||||
kategoriId: t.String(),
|
||||
imageId: t.String(),
|
||||
content: t.String(),
|
||||
}),
|
||||
@@ -35,7 +35,7 @@ const PotensiDesa = new Elysia({
|
||||
body: t.Object({
|
||||
name: t.String(),
|
||||
deskripsi: t.String(),
|
||||
kategori: t.String(),
|
||||
kategoriId: t.String(),
|
||||
imageId: t.String(),
|
||||
content: t.String(),
|
||||
}),
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
|
||||
type FormCreate = {
|
||||
nama: string;
|
||||
}
|
||||
|
||||
export default async function kategoriPotensiCreate(context: Context) {
|
||||
const body = (await context.body) as FormCreate;
|
||||
|
||||
try {
|
||||
const result = await prisma.kategoriPotensi.create({
|
||||
data: {
|
||||
nama: body.nama
|
||||
},
|
||||
});
|
||||
return {
|
||||
success: true,
|
||||
message: "Berhasil membuat kategori potensi",
|
||||
data: result,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Error creating kategori potensi:", error);
|
||||
throw new Error("Gagal membuat kategori potensi: " + (error as Error).message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
|
||||
export default async function kategoriPotensiDelete(context: Context) {
|
||||
const id = context.params.id as string;
|
||||
|
||||
await prisma.kategoriPotensi.delete({
|
||||
where: { id },
|
||||
});
|
||||
|
||||
return {
|
||||
status: 200,
|
||||
success: true,
|
||||
message: "Success delete kategori potensi",
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
|
||||
export default async function kategoriPotensiFindMany() {
|
||||
const data = await prisma.kategoriPotensi.findMany();
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Success get all kategori potensi",
|
||||
data,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
|
||||
export default async function kategoriBukuFindUnique(request: Request) {
|
||||
const url = new URL(request.url);
|
||||
const pathSegments = url.pathname.split('/');
|
||||
const id = pathSegments[pathSegments.length - 1];
|
||||
|
||||
if (!id) {
|
||||
return {
|
||||
success: false,
|
||||
message: "ID is required",
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (typeof id !== 'string') {
|
||||
return {
|
||||
success: false,
|
||||
message: "ID is required",
|
||||
}
|
||||
}
|
||||
|
||||
const data = await prisma.kategoriPotensi.findUnique({
|
||||
where: { id },
|
||||
});
|
||||
|
||||
if (!data) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Data not found",
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Success get kategori potensi",
|
||||
data,
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Find by ID error:", error);
|
||||
return {
|
||||
success: false,
|
||||
message: "Gagal mengambil data: " + (error instanceof Error ? error.message : 'Unknown error'),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import Elysia, { t } from "elysia";
|
||||
import kategoriPotensiCreate from "./create";
|
||||
import kategoriPotensiDelete from "./del";
|
||||
import kategoriPotensiFindMany from "./findMany";
|
||||
import kategoriPotensiFindUnique from "./findUnique";
|
||||
import kategoriPotensiUpdate from "./updt";
|
||||
|
||||
const KategoriPotensi = new Elysia({
|
||||
prefix: "/kategoripotensi",
|
||||
tags: ["Desa / Potensi"],
|
||||
})
|
||||
|
||||
.post("/create", kategoriPotensiCreate, {
|
||||
body: t.Object({
|
||||
nama: t.String(),
|
||||
}),
|
||||
})
|
||||
|
||||
.get("/findMany", kategoriPotensiFindMany)
|
||||
.get("/:id", async (context) => {
|
||||
const response = await kategoriPotensiFindUnique(
|
||||
new Request(context.request)
|
||||
);
|
||||
return response;
|
||||
})
|
||||
.put("/:id", kategoriPotensiUpdate, {
|
||||
body: t.Object({
|
||||
nama: t.String(),
|
||||
}),
|
||||
})
|
||||
.delete("/del/:id", kategoriPotensiDelete);
|
||||
|
||||
export default KategoriPotensi;
|
||||
@@ -0,0 +1,28 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
|
||||
type FormUpdate = {
|
||||
nama: string;
|
||||
}
|
||||
|
||||
export default async function kategoriPotensiUpdate(context: Context) {
|
||||
const body = (await context.body) as FormUpdate;
|
||||
const id = context.params.id as string;
|
||||
|
||||
try {
|
||||
const result = await prisma.kategoriPotensi.update({
|
||||
where: { id },
|
||||
data: {
|
||||
nama: body.nama,
|
||||
},
|
||||
});
|
||||
return {
|
||||
success: true,
|
||||
message: "Berhasil mengupdate kategori potensi",
|
||||
data: result,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Error updating kategori potensi:", error);
|
||||
throw new Error("Gagal mengupdate kategori potensi: " + (error as Error).message);
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ type FormUpdate = Prisma.PotensiDesaGetPayload<{
|
||||
id: true;
|
||||
name: true;
|
||||
deskripsi: true;
|
||||
kategori: true;
|
||||
kategoriId: true;
|
||||
imageId: true;
|
||||
content: true;
|
||||
};
|
||||
@@ -23,7 +23,7 @@ export default async function potensiDesaUpdate(context: Context) {
|
||||
const {
|
||||
name,
|
||||
deskripsi,
|
||||
kategori,
|
||||
kategoriId,
|
||||
imageId,
|
||||
content,
|
||||
} = body;
|
||||
@@ -39,6 +39,7 @@ export default async function potensiDesaUpdate(context: Context) {
|
||||
where: { id },
|
||||
include: {
|
||||
image: true,
|
||||
kategori: true
|
||||
}
|
||||
});
|
||||
|
||||
@@ -69,7 +70,7 @@ export default async function potensiDesaUpdate(context: Context) {
|
||||
data: {
|
||||
name,
|
||||
deskripsi,
|
||||
kategori,
|
||||
kategoriId,
|
||||
imageId,
|
||||
content,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user