Fix Admin - User Menu Keamanan, Submenu Laporan Kontak Darurat, Laporan Publik
This commit is contained in:
@@ -3,7 +3,7 @@ import { Context } from "elysia";
|
||||
|
||||
type FormCreate = {
|
||||
nama: string;
|
||||
imageId?: string;
|
||||
icon: string;
|
||||
kategoriId: string[];
|
||||
};
|
||||
export default async function kontakDaruratKeamananCreate(context: Context) {
|
||||
@@ -18,7 +18,7 @@ export default async function kontakDaruratKeamananCreate(context: Context) {
|
||||
const kontakDaruratKeamanan = await prisma.kontakDaruratKeamanan.create({
|
||||
data: {
|
||||
nama: body.nama,
|
||||
imageId: body.imageId,
|
||||
icon: body.icon,
|
||||
kategoriId: body.kategoriId[0],
|
||||
},
|
||||
});
|
||||
@@ -33,7 +33,6 @@ export default async function kontakDaruratKeamananCreate(context: Context) {
|
||||
return await prisma.kontakDaruratKeamanan.findUnique({
|
||||
where: { id: kontakDaruratKeamanan.id },
|
||||
include: {
|
||||
image: true,
|
||||
kategori: true,
|
||||
kontakItems: {
|
||||
include: {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
import fs from "fs/promises";
|
||||
import path from "path";
|
||||
|
||||
export default async function kontakDaruratKeamananDelete(context: Context) {
|
||||
const { params } = context;
|
||||
@@ -19,9 +17,6 @@ export default async function kontakDaruratKeamananDelete(context: Context) {
|
||||
|
||||
const kontakDaruratKeamanan = await prisma.kontakDaruratKeamanan.findUnique({
|
||||
where: { id },
|
||||
include: {
|
||||
image: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!kontakDaruratKeamanan) {
|
||||
@@ -31,21 +26,6 @@ export default async function kontakDaruratKeamananDelete(context: Context) {
|
||||
};
|
||||
}
|
||||
|
||||
if (kontakDaruratKeamanan.image) {
|
||||
try {
|
||||
const filePath = path.join(
|
||||
kontakDaruratKeamanan.image.path,
|
||||
kontakDaruratKeamanan.image.name
|
||||
);
|
||||
await fs.unlink(filePath);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: kontakDaruratKeamanan.image.id },
|
||||
});
|
||||
} catch (err) {
|
||||
console.error("Gagal hapus file image:", err);
|
||||
}
|
||||
}
|
||||
|
||||
await prisma.kontakDaruratKeamanan.delete({
|
||||
where: { id },
|
||||
});
|
||||
|
||||
@@ -14,7 +14,10 @@ export default async function kontakDaruratKeamananFindMany(context: Context) {
|
||||
|
||||
// Tambahkan pencarian (jika ada)
|
||||
if (search) {
|
||||
where.OR = [{ nama: { contains: search, mode: "insensitive" } }];
|
||||
where.OR = [
|
||||
{ nama: { contains: search, mode: "insensitive" } },
|
||||
{ kontakItems: { some: { kontakItem: { nama: { contains: search, mode: "insensitive" } } } } },
|
||||
];
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -27,7 +30,6 @@ export default async function kontakDaruratKeamananFindMany(context: Context) {
|
||||
|
||||
},
|
||||
},
|
||||
image: true,
|
||||
kategori: true,
|
||||
},
|
||||
skip,
|
||||
|
||||
@@ -16,15 +16,11 @@ export default async function kontakDaruratKeamananFindUnique(
|
||||
include: {
|
||||
kontakItems: {
|
||||
include: {
|
||||
kontakItem: {
|
||||
include: {
|
||||
image: true
|
||||
}
|
||||
},
|
||||
kontakItem: true,
|
||||
|
||||
},
|
||||
},
|
||||
image: true,
|
||||
kategori: true,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ const KontakDaruratKeamanan = new Elysia({
|
||||
.post("/create", kontakDaruratKeamananCreate, {
|
||||
body: t.Object({
|
||||
nama: t.String(),
|
||||
imageId: t.Optional(t.String()),
|
||||
icon: t.String(),
|
||||
kategoriId: t.Array(t.String()),
|
||||
}),
|
||||
})
|
||||
@@ -41,7 +41,7 @@ const KontakDaruratKeamanan = new Elysia({
|
||||
}),
|
||||
body: t.Object({
|
||||
nama: t.String(),
|
||||
imageId: t.Optional(t.String()),
|
||||
icon: t.String(),
|
||||
kategoriId: t.Array(t.String()),
|
||||
}),
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Context } from "elysia";
|
||||
type FormCreate = {
|
||||
nama: string;
|
||||
nomorTelepon: string;
|
||||
imageId?: string;
|
||||
icon: string;
|
||||
};
|
||||
export default async function kontakItemCreate(context: Context){
|
||||
const body = context.body as FormCreate
|
||||
@@ -13,7 +13,7 @@ export default async function kontakItemCreate(context: Context){
|
||||
data: {
|
||||
nama: body.nama,
|
||||
nomorTelepon: body.nomorTelepon,
|
||||
imageId: body.imageId,
|
||||
icon: body.icon,
|
||||
},
|
||||
})
|
||||
return {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
import fs from "fs/promises";
|
||||
import path from "path";
|
||||
|
||||
export default async function kontakItemDelete(context: Context){
|
||||
const id = context.params?.id as string;
|
||||
@@ -15,9 +13,6 @@ export default async function kontakItemDelete(context: Context){
|
||||
|
||||
const kontakItem = await prisma.kontakItem.findUnique({
|
||||
where: { id },
|
||||
include: {
|
||||
image: true
|
||||
}
|
||||
});
|
||||
|
||||
if (!kontakItem) {
|
||||
@@ -27,18 +22,6 @@ export default async function kontakItemDelete(context: Context){
|
||||
};
|
||||
}
|
||||
|
||||
if (kontakItem.image) {
|
||||
try {
|
||||
const filePath = path.join(kontakItem.image.path, kontakItem.image.name);
|
||||
await fs.unlink(filePath);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: kontakItem.image.id },
|
||||
});
|
||||
} catch (err) {
|
||||
console.error("Gagal hapus file image:", err);
|
||||
}
|
||||
}
|
||||
|
||||
await prisma.kontakItem.delete({
|
||||
where: { id },
|
||||
});
|
||||
|
||||
@@ -22,9 +22,6 @@ export default async function kontakItemFindMany(context: Context) {
|
||||
try {
|
||||
const [data, total] = await Promise.all([
|
||||
prisma.kontakItem.findMany({
|
||||
include: {
|
||||
image: true,
|
||||
},
|
||||
skip,
|
||||
take: limit,
|
||||
orderBy: { createdAt: "desc" },
|
||||
|
||||
@@ -30,9 +30,6 @@ export default async function kontakItemFindUnique(
|
||||
|
||||
const data = await prisma.kontakItem.findUnique({
|
||||
where: { id },
|
||||
include: {
|
||||
image: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!data) {
|
||||
|
||||
@@ -17,7 +17,7 @@ const KontakItem = new Elysia({
|
||||
.post("/create", kontakItemCreate, {
|
||||
body: t.Object({
|
||||
nama: t.String(),
|
||||
imageId: t.Optional(t.String()),
|
||||
icon: t.String(),
|
||||
nomorTelepon: t.String(),
|
||||
}),
|
||||
})
|
||||
@@ -31,7 +31,7 @@ const KontakItem = new Elysia({
|
||||
{
|
||||
body: t.Object({
|
||||
nama: t.String(),
|
||||
imageId: t.Optional(t.String()),
|
||||
icon: t.String(),
|
||||
nomorTelepon: t.String(),
|
||||
|
||||
}),
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Context } from "elysia";
|
||||
type FormUpdate = {
|
||||
nama: string;
|
||||
nomorTelepon: string;
|
||||
imageId?: string;
|
||||
icon: string;
|
||||
};
|
||||
|
||||
export default async function kontakItemUpdate(context: Context){
|
||||
@@ -18,10 +18,7 @@ export default async function kontakItemUpdate(context: Context){
|
||||
data: {
|
||||
nama: body.nama,
|
||||
nomorTelepon: body.nomorTelepon,
|
||||
imageId: body.imageId,
|
||||
},
|
||||
include: {
|
||||
image: true,
|
||||
icon: body.icon,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Context } from "elysia";
|
||||
type FormUpdate = {
|
||||
id: string;
|
||||
nama: string;
|
||||
imageId?: string;
|
||||
icon: string;
|
||||
kategoriId: string[];
|
||||
};
|
||||
|
||||
@@ -23,7 +23,7 @@ export default async function kontakDaruratKeamananUpdate(context: Context) {
|
||||
where: { id: body.id },
|
||||
data: {
|
||||
nama: body.nama,
|
||||
imageId: body.imageId,
|
||||
icon: body.icon,
|
||||
kategoriId: body.kategoriId[0],
|
||||
},
|
||||
});
|
||||
@@ -42,7 +42,6 @@ export default async function kontakDaruratKeamananUpdate(context: Context) {
|
||||
const updated = await prisma.kontakDaruratKeamanan.findUnique({
|
||||
where: { id: body.id },
|
||||
include: {
|
||||
image: true,
|
||||
kategori: true,
|
||||
kontakItems: {
|
||||
include: {
|
||||
|
||||
@@ -5,13 +5,11 @@ type LaporanPublikInput = {
|
||||
judul: string;
|
||||
lokasi: string;
|
||||
tanggalWaktu: string;
|
||||
status: "Selesai" | "Proses" | "Gagal";
|
||||
penanganan: string;
|
||||
kronologi?: string;
|
||||
};
|
||||
|
||||
const laporanPublikCreate = async (context: Context) => {
|
||||
const { judul, lokasi, tanggalWaktu, status, penanganan, kronologi } =
|
||||
const { judul, lokasi, tanggalWaktu, kronologi } =
|
||||
(await context.body) as LaporanPublikInput;
|
||||
|
||||
const createdLaporanPublik = await prisma.laporanPublik.create({
|
||||
@@ -19,16 +17,7 @@ const laporanPublikCreate = async (context: Context) => {
|
||||
judul,
|
||||
lokasi,
|
||||
tanggalWaktu: new Date(tanggalWaktu),
|
||||
status,
|
||||
penanganan: {
|
||||
create: {
|
||||
deskripsi: penanganan,
|
||||
},
|
||||
},
|
||||
kronologi,
|
||||
},
|
||||
include: {
|
||||
penanganan: true,
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -14,12 +14,6 @@ const LaporanPublik = new Elysia({
|
||||
judul: t.String(),
|
||||
lokasi: t.String(),
|
||||
tanggalWaktu: t.String(), // ISO string
|
||||
status: t.Union([
|
||||
t.Literal("Selesai"),
|
||||
t.Literal("Proses"),
|
||||
t.Literal("Gagal"),
|
||||
]),
|
||||
penanganan: t.String(), // 🛠️ ARRAY of strings
|
||||
kronologi: t.Optional(t.String()),
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
|
||||
type LaporanPublikUpdateInput = {
|
||||
judul: string;
|
||||
lokasi: string;
|
||||
tanggalWaktu: string;
|
||||
status: "Selesai" | "Proses" | "Gagal";
|
||||
penanganan: string;
|
||||
judul?: string;
|
||||
lokasi?: string;
|
||||
tanggalWaktu?: string;
|
||||
status?: "Selesai" | "Proses" | "Gagal";
|
||||
kronologi?: string;
|
||||
penanganan?: string;
|
||||
};
|
||||
|
||||
const LaporanPublikUpdate = async (context: Context) => {
|
||||
@@ -15,28 +16,35 @@ const LaporanPublikUpdate = async (context: Context) => {
|
||||
const { judul, lokasi, tanggalWaktu, status, penanganan, kronologi } =
|
||||
(await context.body) as LaporanPublikUpdateInput;
|
||||
|
||||
await prisma.penangananLaporanPublik.deleteMany({
|
||||
where: {
|
||||
laporanId: id,
|
||||
},
|
||||
});
|
||||
// Prepare update data with only provided fields
|
||||
const updateData: any = {};
|
||||
|
||||
if (judul !== undefined) updateData.judul = judul;
|
||||
if (lokasi !== undefined) updateData.lokasi = lokasi;
|
||||
if (tanggalWaktu !== undefined) updateData.tanggalWaktu = new Date(tanggalWaktu);
|
||||
if (status !== undefined) updateData.status = status;
|
||||
if (kronologi !== undefined) updateData.kronologi = kronologi;
|
||||
|
||||
const updated = await prisma.laporanPublik.update({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
data: {
|
||||
judul,
|
||||
lokasi,
|
||||
tanggalWaktu: new Date(tanggalWaktu),
|
||||
status,
|
||||
kronologi,
|
||||
penanganan: {
|
||||
// Handle penanganan update if provided
|
||||
if (penanganan !== undefined) {
|
||||
// Delete existing penanganan
|
||||
await prisma.penangananLaporanPublik.deleteMany({
|
||||
where: { laporanId: id },
|
||||
});
|
||||
|
||||
// Add new penanganan if not empty
|
||||
if (penanganan.trim()) {
|
||||
updateData.penanganan = {
|
||||
create: {
|
||||
deskripsi: penanganan,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const updated = await prisma.laporanPublik.update({
|
||||
where: { id },
|
||||
data: updateData,
|
||||
include: {
|
||||
penanganan: true,
|
||||
},
|
||||
|
||||
@@ -4,6 +4,7 @@ import { Context } from "elysia";
|
||||
type ArtikelKesehatanInput = {
|
||||
title: string;
|
||||
content: string;
|
||||
imageId: string;
|
||||
introduction: {content: string};
|
||||
symptom: {title: string; content: string};
|
||||
prevention: {title: string; content: string};
|
||||
@@ -14,7 +15,7 @@ type ArtikelKesehatanInput = {
|
||||
|
||||
const artikelKesehatanCreate = async (context: Context) => {
|
||||
const body = await context.body as ArtikelKesehatanInput;
|
||||
const { title, content, introduction, symptom, prevention, firstAid, mythVsFact, doctorSign } = body;
|
||||
const { title, content, introduction, symptom, prevention, firstAid, mythVsFact, doctorSign, imageId } = body;
|
||||
|
||||
const [createdIntroduction, createdSymptom, createdPrevention, createdFirstAid, createdMythVsFact, createdDoctorSign] = await Promise.all([
|
||||
prisma.introduction.create({ data: introduction }),
|
||||
@@ -29,6 +30,7 @@ const artikelKesehatanCreate = async (context: Context) => {
|
||||
data: {
|
||||
title,
|
||||
content,
|
||||
imageId,
|
||||
introductionId: createdIntroduction.id,
|
||||
symptomId: createdSymptom.id,
|
||||
preventionId: createdPrevention.id,
|
||||
@@ -37,6 +39,7 @@ const artikelKesehatanCreate = async (context: Context) => {
|
||||
doctorSignId: createdDoctorSign.id,
|
||||
},
|
||||
include: {
|
||||
image: true,
|
||||
introduction: true,
|
||||
symptom: true,
|
||||
prevention: true,
|
||||
|
||||
@@ -37,6 +37,7 @@ export default async function artikelKesehatanFindMany(context: Context) {
|
||||
firstaid: true,
|
||||
mythvsfact: true,
|
||||
doctorsign: true,
|
||||
image: true,
|
||||
},
|
||||
skip,
|
||||
take: limit,
|
||||
|
||||
@@ -29,6 +29,7 @@ export async function artikelKesehatanFindUnique(request: Request) {
|
||||
firstaid: true,
|
||||
mythvsfact: true,
|
||||
doctorsign: true,
|
||||
image: true,
|
||||
}
|
||||
})
|
||||
if (!data) {
|
||||
|
||||
@@ -36,6 +36,7 @@ const ArtikelKesehatan = new Elysia({
|
||||
doctorSign: t.Object({
|
||||
content: t.String(),
|
||||
}),
|
||||
imageId: t.String(),
|
||||
}),
|
||||
})
|
||||
.get("/find-many", artikelKesehatanFindMany)
|
||||
@@ -79,6 +80,7 @@ const ArtikelKesehatan = new Elysia({
|
||||
doctorSign: t.Object({
|
||||
content: t.String(),
|
||||
}),
|
||||
imageId: t.String(),
|
||||
}),
|
||||
}
|
||||
);
|
||||
|
||||
@@ -4,6 +4,7 @@ import { Context } from "elysia";
|
||||
type ArtikelKesehatanInput = {
|
||||
title: string;
|
||||
content: string;
|
||||
imageId: string;
|
||||
introduction: { content: string };
|
||||
symptom: { title: string; content: string };
|
||||
prevention: { title: string; content: string };
|
||||
@@ -51,6 +52,7 @@ const artikelKesehatanUpdate = async (context: Context) => {
|
||||
firstAid,
|
||||
mythVsFact,
|
||||
doctorSign,
|
||||
imageId,
|
||||
} = body;
|
||||
|
||||
await Promise.all([
|
||||
@@ -84,7 +86,8 @@ const artikelKesehatanUpdate = async (context: Context) => {
|
||||
where: { id },
|
||||
data: {
|
||||
title,
|
||||
content
|
||||
content,
|
||||
imageId,
|
||||
},
|
||||
include: {
|
||||
introduction: true,
|
||||
@@ -93,6 +96,7 @@ const artikelKesehatanUpdate = async (context: Context) => {
|
||||
firstaid: true,
|
||||
mythvsfact: true,
|
||||
doctorsign: true,
|
||||
image: true,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user