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: {
|
||||
|
||||
Reference in New Issue
Block a user