Membuat database menu desa: Berita & Pengummuman
This commit is contained in:
9
src/app/api/[[...slugs]]/_lib/desa/berita/category.ts
Normal file
9
src/app/api/[[...slugs]]/_lib/desa/berita/category.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
|
||||
async function katagoryBeritaFindMany() {
|
||||
const data = await prisma.katagoryBerita.findMany();
|
||||
return { data };
|
||||
}
|
||||
|
||||
export default katagoryBeritaFindMany
|
||||
|
||||
39
src/app/api/[[...slugs]]/_lib/desa/berita/create.ts
Normal file
39
src/app/api/[[...slugs]]/_lib/desa/berita/create.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { Context } from "elysia";
|
||||
|
||||
type FormCreate = Prisma.BeritaGetPayload<{
|
||||
select: {
|
||||
judul: true;
|
||||
deskripsi: true;
|
||||
image: true;
|
||||
content: true;
|
||||
katagoryBeritaId: true;
|
||||
};
|
||||
}>;
|
||||
async function beritaCreate(context: Context) {
|
||||
const body = context.body as FormCreate;
|
||||
|
||||
// console.log(body)
|
||||
|
||||
await prisma.berita.create({
|
||||
data: {
|
||||
content: body.content,
|
||||
deskripsi: body.deskripsi,
|
||||
image: body.image,
|
||||
judul: body.judul,
|
||||
katagoryBeritaId: body.katagoryBeritaId,
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Success create berita",
|
||||
data: {
|
||||
...body,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default beritaCreate
|
||||
|
||||
8
src/app/api/[[...slugs]]/_lib/desa/berita/find-many.ts
Normal file
8
src/app/api/[[...slugs]]/_lib/desa/berita/find-many.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
|
||||
export default async function beritaFindMany() {
|
||||
const res = await prisma.berita.findMany();
|
||||
return {
|
||||
data: res,
|
||||
};
|
||||
}
|
||||
19
src/app/api/[[...slugs]]/_lib/desa/berita/index.ts
Normal file
19
src/app/api/[[...slugs]]/_lib/desa/berita/index.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import Elysia, { t } from "elysia";
|
||||
import katagoryBeritaFindMany 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("/find-many", beritaFindMany)
|
||||
.post("/create", beritaCreate, {
|
||||
body: t.Object({
|
||||
judul: t.String(),
|
||||
deskripsi: t.String(),
|
||||
image: t.String(),
|
||||
content: t.String(),
|
||||
katagoryBeritaId: t.Union([t.String(), t.Null()]),
|
||||
}),
|
||||
});
|
||||
|
||||
export default Berita;
|
||||
9
src/app/api/[[...slugs]]/_lib/desa/index.ts
Normal file
9
src/app/api/[[...slugs]]/_lib/desa/index.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import Elysia from "elysia";
|
||||
import Berita from "./berita";
|
||||
import Pengumuman from "./pengumuman";
|
||||
|
||||
const Desa = new Elysia({ prefix: "/api/desa", tags: ["Desa"] })
|
||||
.use(Berita)
|
||||
.use(Pengumuman)
|
||||
|
||||
export default Desa;
|
||||
@@ -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;
|
||||
36
src/app/api/[[...slugs]]/_lib/landing_page/layanan.ts
Normal file
36
src/app/api/[[...slugs]]/_lib/landing_page/layanan.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { MODEL_LANDING_PAGE_LAYANAN } from "@/app/admin/(dashboard)/landing-page/layanan/lib/interface";
|
||||
import prisma from "@/lib/prisma";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function layanan_landingpage({req} : {req: MODEL_LANDING_PAGE_LAYANAN}) {
|
||||
try {
|
||||
const data = await prisma.landingPage_Layanan.create({
|
||||
data: {
|
||||
id: req.id,
|
||||
deksripsi: req.deskripsi
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
deksripsi: true
|
||||
}
|
||||
})
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Success get collaboration",
|
||||
data: data,
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("Error create layanan", error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Error create layanan",
|
||||
reason: (error as Error).message,
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2,16 +2,17 @@ import prisma from "@/lib/prisma";
|
||||
import cors, { HTTPMethod } from "@elysiajs/cors";
|
||||
import swagger from "@elysiajs/swagger";
|
||||
import { Elysia, t } from "elysia";
|
||||
import getPotensi from "./_lib/get-potensi";
|
||||
import img from "./_lib/img";
|
||||
import fs from "fs/promises";
|
||||
import path from "path";
|
||||
import uplImg from "./_lib/upl-img";
|
||||
import getPotensi from "./_lib/get-potensi";
|
||||
import img from "./_lib/img";
|
||||
import imgDel from "./_lib/img-del";
|
||||
import imgs from "./_lib/imgs";
|
||||
import uplCsv from "./_lib/upl-csv";
|
||||
import imgDel from "./_lib/img-del";
|
||||
import { uplImgSingle } from "./_lib/upl-img-single";
|
||||
import { uplCsvSingle } from "./_lib/upl-csv-single";
|
||||
import uplImg from "./_lib/upl-img";
|
||||
import { uplImgSingle } from "./_lib/upl-img-single";
|
||||
import Desa from "./_lib/desa";
|
||||
const ROOT = process.cwd();
|
||||
|
||||
if (!process.env.WIBU_UPLOAD_DIR)
|
||||
@@ -46,6 +47,7 @@ async function layanan() {
|
||||
const ApiServer = new Elysia()
|
||||
.use(swagger({ path: "/api/docs" }))
|
||||
.use(cors(corsConfig))
|
||||
.use(Desa)
|
||||
.onError(({ code }) => {
|
||||
if (code === "NOT_FOUND") {
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user