fix(storage): migrate domain-specific delete and update handlers to MinIO
- Replaces local filesystem operations (fs.unlink, path.join) with MinIO removeObject in all domain lib handlers - Updated handlers for: Berita, GalleryFoto, Layanan, Musik, Penghargaan, Potensi, Profile, Inovasi, Keamanan, Kesehatan, LandingPage, and PPID - bump: version 0.1.19 -> 0.1.20
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "desa-darmasaba",
|
||||
"version": "0.1.19",
|
||||
"version": "0.1.20",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
import fs from "fs/promises";
|
||||
import path from "path";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
const beritaDelete = async (context: Context) => {
|
||||
const id = context.params?.id as string;
|
||||
@@ -21,14 +20,15 @@ const beritaDelete = async (context: Context) => {
|
||||
// 2. BARU HAPUS FILE
|
||||
if (berita.image) {
|
||||
try {
|
||||
const filePath = path.join(berita.image.path, berita.image.name);
|
||||
await fs.unlink(filePath);
|
||||
// Hapus dari MinIO
|
||||
await minio.removeObject(MINIO_BUCKET, `${berita.image.path}/${berita.image.name}`);
|
||||
|
||||
// Hapus dari database
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: berita.image.id },
|
||||
});
|
||||
} catch (err) {
|
||||
console.error("Gagal hapus file image:", err);
|
||||
console.error("Gagal hapus file image dari MinIO/DB:", err);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import fs from "fs/promises";
|
||||
import path from "path";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
type FormUpdate = {
|
||||
id: string;
|
||||
@@ -50,8 +49,7 @@ async function beritaUpdate(context: Context) {
|
||||
const oldImage = existing.image;
|
||||
if (oldImage) {
|
||||
try {
|
||||
const filePath = path.join(oldImage.path, oldImage.name);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${oldImage.path}/${oldImage.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: oldImage.id },
|
||||
});
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
import fs from "fs/promises";
|
||||
import path from "path";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
const galleryFotoDelete = async (context: Context) => {
|
||||
const id = context.params?.id as string;
|
||||
@@ -30,8 +29,7 @@ const galleryFotoDelete = async (context: Context) => {
|
||||
// Hapus file gambar dari filesystem jika ada
|
||||
if (foto.imageGalleryFoto) {
|
||||
try {
|
||||
const filePath = path.join(foto.imageGalleryFoto.path, foto.imageGalleryFoto.name);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${foto.imageGalleryFoto.path}/${foto.imageGalleryFoto.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: foto.imageGalleryFoto.id },
|
||||
});
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { Context } from "elysia";
|
||||
import fs from "fs/promises";
|
||||
import path from "path";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
type FormUpdate = Prisma.GalleryFotoGetPayload<{
|
||||
select: {
|
||||
@@ -48,8 +47,7 @@ async function galleryFotoUpdate(context: Context) {
|
||||
const oldImage = existing.imageGalleryFoto;
|
||||
if (oldImage) {
|
||||
try {
|
||||
const filePath = path.join(oldImage.path, oldImage.name);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${oldImage.path}/${oldImage.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: oldImage.id },
|
||||
});
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
import path from "path";
|
||||
import fs from "fs/promises";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
const pelayananSuratKeteranganDelete = async (context: Context) => {
|
||||
const id = context.params?.id as string;
|
||||
@@ -31,8 +30,7 @@ const pelayananSuratKeteranganDelete = async (context: Context) => {
|
||||
// Hapus file gambar dari filesystem jika ada
|
||||
if (pelayananSuratKeterangan.image) {
|
||||
try {
|
||||
const filePath = path.join(pelayananSuratKeterangan.image.path, pelayananSuratKeterangan.image.name);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${pelayananSuratKeterangan.image.path}/${pelayananSuratKeterangan.image.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: pelayananSuratKeterangan.image.id },
|
||||
});
|
||||
@@ -43,8 +41,7 @@ const pelayananSuratKeteranganDelete = async (context: Context) => {
|
||||
|
||||
if (pelayananSuratKeterangan.image2) {
|
||||
try {
|
||||
const filePath = path.join(pelayananSuratKeterangan.image2.path, pelayananSuratKeterangan.image2.name);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${pelayananSuratKeterangan.image2.path}/${pelayananSuratKeterangan.image2.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: pelayananSuratKeterangan.image2.id },
|
||||
});
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import path from "path";
|
||||
import fs from "fs/promises";
|
||||
import { Context } from "elysia";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
type FormUpdate = Prisma.PelayananSuratKeteranganGetPayload<{
|
||||
select: {
|
||||
@@ -34,6 +33,7 @@ export default async function updatePelayananSuratKeterangan(context: Context) {
|
||||
where: { id },
|
||||
include: {
|
||||
image: true,
|
||||
image2: true,
|
||||
}
|
||||
});
|
||||
|
||||
@@ -53,8 +53,7 @@ export default async function updatePelayananSuratKeterangan(context: Context) {
|
||||
const oldImage = existing.image;
|
||||
if (oldImage) {
|
||||
try {
|
||||
const filePath = path.join(oldImage.path, oldImage.name);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${oldImage.path}/${oldImage.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: oldImage.id },
|
||||
});
|
||||
@@ -65,11 +64,10 @@ export default async function updatePelayananSuratKeterangan(context: Context) {
|
||||
}
|
||||
|
||||
if (existing.image2Id && existing.image2Id !== image2Id) {
|
||||
const oldImage = existing.image;
|
||||
const oldImage = existing.image2;
|
||||
if (oldImage) {
|
||||
try {
|
||||
const filePath = path.join(oldImage.path, oldImage.name);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${oldImage.path}/${oldImage.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: oldImage.id },
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Context } from "elysia";
|
||||
import prisma from "@/lib/prisma";
|
||||
import path from "path";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
const musikDelete = async (context: Context) => {
|
||||
const { id } = context.params as { id: string };
|
||||
@@ -18,9 +18,7 @@ const musikDelete = async (context: Context) => {
|
||||
// 2. HAPUS FILE AUDIO (jika ada)
|
||||
if (musik.audioFile) {
|
||||
try {
|
||||
const fs = await import("fs/promises");
|
||||
const filePath = path.join(musik.audioFile.path, musik.audioFile.name);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${musik.audioFile.path}/${musik.audioFile.name}`);
|
||||
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: musik.audioFile.id },
|
||||
@@ -33,9 +31,7 @@ const musikDelete = async (context: Context) => {
|
||||
// 3. HAPUS FILE COVER (jika ada)
|
||||
if (musik.coverImage) {
|
||||
try {
|
||||
const fs = await import("fs/promises");
|
||||
const filePath = path.join(musik.coverImage.path, musik.coverImage.name);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${musik.coverImage.path}/${musik.coverImage.name}`);
|
||||
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: musik.coverImage.id },
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
import fs from "fs/promises";
|
||||
import path from "path";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
const penghargaanDelete = async (context: Context) => {
|
||||
const id = context.params?.id as string;
|
||||
@@ -29,8 +28,7 @@ const penghargaanDelete = async (context: Context) => {
|
||||
|
||||
if (penghargaan.image) {
|
||||
try {
|
||||
const filePath = path.join(penghargaan.image.path, penghargaan.image.name);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${penghargaan.image.path}/${penghargaan.image.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: penghargaan.image.id },
|
||||
});
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import path from "path";
|
||||
import fs from "fs/promises";
|
||||
import { Context } from "elysia";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
type FormUpdate = Prisma.PenghargaanGetPayload<{
|
||||
select: {
|
||||
@@ -60,8 +59,7 @@ try {
|
||||
const oldImage = existing.image;
|
||||
if (oldImage) {
|
||||
try {
|
||||
const filePath = path.join(oldImage.path, oldImage.name);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${oldImage.path}/${oldImage.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: oldImage.id },
|
||||
});
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import path from "path";
|
||||
import { Context } from "elysia";
|
||||
import fs from "fs/promises";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
const potensiDesaDelete = async (context: Context) => {
|
||||
const id = context.params?.id as string;
|
||||
@@ -31,8 +30,7 @@ const potensiDesaDelete = async (context: Context) => {
|
||||
// Hapus file gambar dari filesystem jika ada
|
||||
if (potensiDesa.image) {
|
||||
try {
|
||||
const filePath = path.join(potensiDesa.image.path, potensiDesa.image.name);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${potensiDesa.image.path}/${potensiDesa.image.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: potensiDesa.image.id },
|
||||
});
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { Context } from "elysia";
|
||||
import path from "path";
|
||||
import fs from "fs/promises";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
type FormUpdate = Prisma.PotensiDesaGetPayload<{
|
||||
select: {
|
||||
@@ -54,8 +53,7 @@ export default async function potensiDesaUpdate(context: Context) {
|
||||
const oldImage = existing.image;
|
||||
if (oldImage) {
|
||||
try {
|
||||
const filePath = path.join(oldImage.path, oldImage.name);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${oldImage.path}/${oldImage.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: oldImage.id },
|
||||
});
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
import fs from "fs/promises";
|
||||
import path from "path";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
const profileMantanPerbekelDelete = async (context: Context) => {
|
||||
const id = context.params?.id as string;
|
||||
@@ -30,8 +29,7 @@ const profileMantanPerbekelDelete = async (context: Context) => {
|
||||
// Hapus file gambar dari filesystem jika ada
|
||||
if (foto.image) {
|
||||
try {
|
||||
const filePath = path.join(foto.image.path, foto.image.name);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${foto.image.path}/${foto.image.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: foto.image.id },
|
||||
});
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { Context } from "elysia";
|
||||
import fs from "fs/promises";
|
||||
import path from "path";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
type FormUpdate = Prisma.PerbekelDariMasaKeMasaGetPayload<{
|
||||
select: {
|
||||
@@ -46,8 +45,7 @@ export default async function profileMantanPerbekelUpdate(context: Context) {
|
||||
const oldImage = existing.image;
|
||||
if (oldImage) {
|
||||
try {
|
||||
const filePath = path.join(oldImage.path, oldImage.name);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${oldImage.path}/${oldImage.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: oldImage.id },
|
||||
});
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { Context } from "elysia";
|
||||
import path from "path";
|
||||
import fs from "fs/promises";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
type FormUpdate = Prisma.ProfilPerbekelGetPayload<{
|
||||
select: {
|
||||
@@ -64,8 +63,7 @@ export default async function profilePerbekelUpdate(context: Context) {
|
||||
const oldImage = exisitng.image;
|
||||
if (oldImage) {
|
||||
try {
|
||||
const filePath = path.join(oldImage.path, oldImage.name);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${oldImage.path}/${oldImage.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: oldImage.id },
|
||||
});
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
import fs from "fs/promises";
|
||||
import path from "path";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
export default async function desaDigitalDelete(context: Context) {
|
||||
const id = context.params?.id as string;
|
||||
@@ -29,11 +28,7 @@ export default async function desaDigitalDelete(context: Context) {
|
||||
|
||||
if (desaDigital.image) {
|
||||
try {
|
||||
const filePath = path.join(
|
||||
desaDigital.image.path,
|
||||
desaDigital.image.name
|
||||
);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${desaDigital.image.path}/${desaDigital.image.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: desaDigital.image.id },
|
||||
});
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { Context } from "elysia";
|
||||
import path from "path";
|
||||
import fs from "fs/promises";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
type FormUpdate = Prisma.DesaDigitalGetPayload<{
|
||||
select: {
|
||||
@@ -58,8 +57,7 @@ export default async function desaDigitalUpdate(context: Context) {
|
||||
const oldImage = existing.image;
|
||||
if (oldImage) {
|
||||
try {
|
||||
const filePath = path.join(oldImage.path, oldImage.name);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${oldImage.path}/${oldImage.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: oldImage.id },
|
||||
});
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
import fs from "fs/promises";
|
||||
import path from "path";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
export default async function infoTeknoDelete(context: Context) {
|
||||
const id = context.params?.id as string;
|
||||
@@ -29,11 +28,7 @@ export default async function infoTeknoDelete(context: Context) {
|
||||
|
||||
if (infoTekno.image) {
|
||||
try {
|
||||
const filePath = path.join(
|
||||
infoTekno.image.path,
|
||||
infoTekno.image.name
|
||||
);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${infoTekno.image.path}/${infoTekno.image.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: infoTekno.image.id },
|
||||
});
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { Context } from "elysia";
|
||||
import path from "path";
|
||||
import fs from "fs/promises";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
type FormUpdate = Prisma.InfoTeknoGetPayload<{
|
||||
select: {
|
||||
@@ -58,8 +57,7 @@ export default async function infoTeknoUpdate(context: Context) {
|
||||
const oldImage = existing.image;
|
||||
if (oldImage) {
|
||||
try {
|
||||
const filePath = path.join(oldImage.path, oldImage.name);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${oldImage.path}/${oldImage.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: oldImage.id },
|
||||
});
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
import fs from "fs/promises";
|
||||
import path from "path";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
export default async function mitraKolaborasiDelete(context: Context) {
|
||||
const id = context.params?.id as string;
|
||||
@@ -29,11 +28,7 @@ export default async function mitraKolaborasiDelete(context: Context) {
|
||||
|
||||
if (mitraKolaborasi.image) {
|
||||
try {
|
||||
const filePath = path.join(
|
||||
mitraKolaborasi.image.path,
|
||||
mitraKolaborasi.image.name
|
||||
);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${mitraKolaborasi.image.path}/${mitraKolaborasi.image.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: mitraKolaborasi.image.id },
|
||||
});
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
import fs from "fs/promises";
|
||||
import path from "path";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
type FormUpdate = {
|
||||
id: string;
|
||||
@@ -12,12 +11,12 @@ export default async function mitraKolaborasiUpdate(context: Context) {
|
||||
try {
|
||||
const id = context.params?.id as string;
|
||||
const body = (await context.body) as Omit<FormUpdate, "id">;
|
||||
|
||||
|
||||
const {
|
||||
name,
|
||||
imageId
|
||||
} = body;
|
||||
|
||||
|
||||
if (!id) {
|
||||
return new Response(JSON.stringify({
|
||||
success: false,
|
||||
@@ -29,14 +28,14 @@ export default async function mitraKolaborasiUpdate(context: Context) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
const existing = await prisma.mitraKolaborasi.findUnique({
|
||||
where: {id},
|
||||
include: {
|
||||
image: true,
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
if (!existing) {
|
||||
return new Response(JSON.stringify({
|
||||
success: false,
|
||||
@@ -48,13 +47,12 @@ export default async function mitraKolaborasiUpdate(context: Context) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
if (existing.imageId && existing.imageId !== imageId) {
|
||||
const oldImage = existing.image;
|
||||
if (oldImage) {
|
||||
try {
|
||||
const filePath = path.join(oldImage.path, oldImage.name);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${oldImage.path}/${oldImage.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: oldImage.id },
|
||||
});
|
||||
@@ -63,7 +61,7 @@ export default async function mitraKolaborasiUpdate(context: Context) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const updated = await prisma.mitraKolaborasi.update({
|
||||
where: { id },
|
||||
data: {
|
||||
@@ -71,7 +69,6 @@ export default async function mitraKolaborasiUpdate(context: Context) {
|
||||
imageId,
|
||||
}
|
||||
})
|
||||
|
||||
return new Response(JSON.stringify({
|
||||
success: true,
|
||||
message: "Mitra kolaborasi berhasil diupdate",
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
import fs from "fs/promises";
|
||||
import path from "path";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
export default async function pengaduanMasyarakatDelete(context: Context) {
|
||||
const id = context.params?.id as string;
|
||||
@@ -25,8 +24,7 @@ export default async function pengaduanMasyarakatDelete(context: Context) {
|
||||
|
||||
if (pengaduan.image) {
|
||||
try {
|
||||
const filePath = path.join(pengaduan.image.path, pengaduan.image.name);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${pengaduan.image.path}/${pengaduan.image.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: pengaduan.image.id },
|
||||
});
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
import path from "path";
|
||||
import fs from "fs/promises";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
const keamananLingkunganDelete = async (context: Context) => {
|
||||
const id = context.params?.id as string;
|
||||
@@ -30,8 +29,7 @@ const keamananLingkunganDelete = async (context: Context) => {
|
||||
// Hapus file gambar dari filesystem jika ada
|
||||
if (keamananLingkungan.image) {
|
||||
try {
|
||||
const filePath = path.join(keamananLingkungan.image.path, keamananLingkungan.image.name);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${keamananLingkungan.image.path}/${keamananLingkungan.image.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: keamananLingkungan.image.id },
|
||||
});
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import path from "path";
|
||||
import fs from "fs/promises";
|
||||
import { Context } from "elysia";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
type FormUpdate = Prisma.KeamananLingkunganGetPayload<{
|
||||
select: {
|
||||
@@ -59,8 +58,7 @@ export default async function updateKeamananLingkungan(context: Context) {
|
||||
const oldImage = existing.image;
|
||||
if (oldImage) {
|
||||
try {
|
||||
const filePath = path.join(oldImage.path, oldImage.name);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${oldImage.path}/${oldImage.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: oldImage.id },
|
||||
});
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
import path from "path";
|
||||
import fs from "fs/promises";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
const menuTipsKeamananDelete = async (context: Context) => {
|
||||
const id = context.params?.id as string;
|
||||
@@ -30,8 +29,7 @@ const menuTipsKeamananDelete = async (context: Context) => {
|
||||
// Hapus file gambar dari filesystem jika ada
|
||||
if (tipsKeamanan.image) {
|
||||
try {
|
||||
const filePath = path.join(tipsKeamanan.image.path, tipsKeamanan.image.name);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${tipsKeamanan.image.path}/${tipsKeamanan.image.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: tipsKeamanan.image.id },
|
||||
});
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import path from "path";
|
||||
import fs from "fs/promises";
|
||||
import { Context } from "elysia";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
|
||||
type MenuTipsKeamananUpdate = Prisma.MenuTipsKeamananGetPayload<{
|
||||
@@ -62,8 +61,7 @@ export default async function menuTipsKeamananUpdate(context: Context) {
|
||||
const oldImage = existing.image;
|
||||
if (oldImage) {
|
||||
try {
|
||||
const filePath = path.join(oldImage.path, oldImage.name);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${oldImage.path}/${oldImage.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: oldImage.id },
|
||||
});
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import fs from "fs/promises";
|
||||
import { Context } from "elysia";
|
||||
import path from "path";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
const infoWabahPenyakitDelete = async (context: Context) => {
|
||||
const id = context.params?.id as string;
|
||||
@@ -28,8 +27,7 @@ const infoWabahPenyakitDelete = async (context: Context) => {
|
||||
// Hapus file gambar dari filesystem jika ada
|
||||
if (infoWabahPenyakit.image) {
|
||||
try {
|
||||
const filePath = path.join(infoWabahPenyakit.image.path, infoWabahPenyakit.image.name);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${infoWabahPenyakit.image.path}/${infoWabahPenyakit.image.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: infoWabahPenyakit.image.id },
|
||||
});
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { Context } from "elysia";
|
||||
import path from "path";
|
||||
import fs from "fs/promises";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
type FormUpdate = Prisma.InfoWabahPenyakitGetPayload<{
|
||||
select: {
|
||||
@@ -61,8 +60,7 @@ export default async function infoWabahPenyakitUpdate(context: Context) {
|
||||
const oldImage = existing.image;
|
||||
if (oldImage) {
|
||||
try {
|
||||
const filePath = path.join(oldImage.path, oldImage.name);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${oldImage.path}/${oldImage.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: oldImage.id },
|
||||
});
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import fs from "fs/promises";
|
||||
import { Context } from "elysia";
|
||||
import path from "path";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
const kontakDaruratDelete = async (context: Context) => {
|
||||
const id = context.params?.id as string;
|
||||
@@ -28,8 +27,7 @@ const kontakDaruratDelete = async (context: Context) => {
|
||||
// Hapus file gambar dari filesystem jika ada
|
||||
if (kontakDarurat.image) {
|
||||
try {
|
||||
const filePath = path.join(kontakDarurat.image.path, kontakDarurat.image.name);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${kontakDarurat.image.path}/${kontakDarurat.image.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: kontakDarurat.image.id },
|
||||
});
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { Context } from "elysia";
|
||||
import path from "path";
|
||||
import fs from "fs/promises";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
type FormUpdate = Prisma.KontakDaruratGetPayload<{
|
||||
select: {
|
||||
@@ -60,8 +59,7 @@ export default async function kontakDaruratUpdate(context: Context) {
|
||||
const oldImage = existing.image;
|
||||
if (oldImage) {
|
||||
try {
|
||||
const filePath = path.join(oldImage.path, oldImage.name);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${oldImage.path}/${oldImage.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: oldImage.id },
|
||||
});
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import fs from "fs/promises";
|
||||
import { Context } from "elysia";
|
||||
import path from "path";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
const penangananDaruratDelete = async (context: Context) => {
|
||||
const id = context.params?.id as string;
|
||||
@@ -27,11 +26,7 @@ const penangananDaruratDelete = async (context: Context) => {
|
||||
// Hapus file gambar dari filesystem jika ada
|
||||
if (penangananDarurat.image) {
|
||||
try {
|
||||
const filePath = path.join(
|
||||
penangananDarurat.image.path,
|
||||
penangananDarurat.image.name
|
||||
);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${penangananDarurat.image.path}/${penangananDarurat.image.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: penangananDarurat.image.id },
|
||||
});
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { Context } from "elysia";
|
||||
import path from "path";
|
||||
import fs from "fs/promises";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
type FormUpdate = Prisma.PenangananDaruratGetPayload<{
|
||||
select: {
|
||||
@@ -58,8 +57,7 @@ export default async function penangananDaruratUpdate(context: Context) {
|
||||
const oldImage = existing.image;
|
||||
if (oldImage) {
|
||||
try {
|
||||
const filePath = path.join(oldImage.path, oldImage.name);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${oldImage.path}/${oldImage.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: oldImage.id },
|
||||
});
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import fs from "fs/promises";
|
||||
import { Context } from "elysia";
|
||||
import path from "path";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
const posyanduDelete = async (context: Context) => {
|
||||
const id = context.params?.id as string;
|
||||
@@ -28,8 +27,7 @@ const posyanduDelete = async (context: Context) => {
|
||||
// Hapus file gambar dari filesystem jika ada
|
||||
if (posyandu.image) {
|
||||
try {
|
||||
const filePath = path.join(posyandu.image.path, posyandu.image.name);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${posyandu.image.path}/${posyandu.image.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: posyandu.image.id },
|
||||
});
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { Context } from "elysia";
|
||||
import path from "path";
|
||||
import fs from "fs/promises";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
type FormUpdate = Prisma.PosyanduGetPayload<{
|
||||
select: {
|
||||
@@ -63,8 +62,7 @@ export default async function posyanduUpdate(context: Context) {
|
||||
const oldImage = existing.image;
|
||||
if (oldImage) {
|
||||
try {
|
||||
const filePath = path.join(oldImage.path, oldImage.name);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${oldImage.path}/${oldImage.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: oldImage.id },
|
||||
});
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import fs from "fs/promises";
|
||||
import { Context } from "elysia";
|
||||
import path from "path";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
const programKesehatanDelete = async (context: Context) => {
|
||||
const id = context.params?.id as string;
|
||||
@@ -28,8 +27,7 @@ const programKesehatanDelete = async (context: Context) => {
|
||||
// Hapus file gambar dari filesystem jika ada
|
||||
if (programKesehatan.image) {
|
||||
try {
|
||||
const filePath = path.join(programKesehatan.image.path, programKesehatan.image.name);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${programKesehatan.image.path}/${programKesehatan.image.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: programKesehatan.image.id },
|
||||
});
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { Context } from "elysia";
|
||||
import path from "path";
|
||||
import fs from "fs/promises";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
type FormUpdate = Prisma.ProgramKesehatanGetPayload<{
|
||||
select: {
|
||||
@@ -61,8 +60,7 @@ export default async function programKesehatanUpdate(context: Context) {
|
||||
const oldImage = existing.image;
|
||||
if (oldImage) {
|
||||
try {
|
||||
const filePath = path.join(oldImage.path, oldImage.name);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${oldImage.path}/${oldImage.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: oldImage.id },
|
||||
});
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
import path from "path";
|
||||
import fs from "fs/promises";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
const puskesmasDelete = async (context: Context) => {
|
||||
const id = context.params?.id as string;
|
||||
@@ -27,8 +26,7 @@ const puskesmasDelete = async (context: Context) => {
|
||||
|
||||
if (puskesmas.image) {
|
||||
try {
|
||||
const filePath = path.join(puskesmas.image.path, puskesmas.image.name);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${puskesmas.image.path}/${puskesmas.image.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: puskesmas.image.id },
|
||||
});
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { Context } from "elysia";
|
||||
import path from "path";
|
||||
import fs from "fs/promises";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
type FormUpdate = Prisma.PuskesmasGetPayload<{
|
||||
select: {
|
||||
@@ -65,8 +64,7 @@ export default async function puskesmasUpdate(context: Context) {
|
||||
const oldImage = existing.image;
|
||||
if (oldImage) {
|
||||
try {
|
||||
const filePath = path.join(oldImage.path, oldImage.name);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${oldImage.path}/${oldImage.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: oldImage.id },
|
||||
});
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { Context } from "elysia";
|
||||
import fs from "fs/promises";
|
||||
import path from "path";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
type FormUpdate = Prisma.PejabatDesaGetPayload<{
|
||||
select: {
|
||||
@@ -62,8 +61,7 @@ export default async function pejabatDesaUpdate(context: Context) {
|
||||
const oldImage = existing.image;
|
||||
if (oldImage) {
|
||||
try {
|
||||
const filePath = path.join(oldImage.path, oldImage.name);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${oldImage.path}/${oldImage.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: oldImage.id },
|
||||
});
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { Context } from "elysia";
|
||||
import fs from "fs/promises";
|
||||
import path from "path";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
type FormUpdate = Prisma.PegawaiPPIDGetPayload<{
|
||||
select: {
|
||||
@@ -80,13 +79,12 @@ export default async function pegawaiUpdate(context: Context) {
|
||||
const oldImage = existing.image;
|
||||
if (oldImage) {
|
||||
try {
|
||||
const filePath = path.join(oldImage.path, oldImage.name);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${oldImage.path}/${oldImage.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: oldImage.id },
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Gagal hapus gambar lama:", error);
|
||||
console.error("Gagal hapus gambar lama dari MinIO/DB:", error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
import path from "path";
|
||||
import fs from "fs/promises";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import minio, { MINIO_BUCKET } from "@/lib/minio";
|
||||
|
||||
type FormUpdate = Prisma.StrukturPPIDGetPayload<{
|
||||
select: {
|
||||
@@ -62,13 +61,12 @@ try {
|
||||
const oldImage = existing.image;
|
||||
if (oldImage) {
|
||||
try {
|
||||
const filePath = path.join(oldImage.path, oldImage.name);
|
||||
await fs.unlink(filePath);
|
||||
await minio.removeObject(MINIO_BUCKET, `${oldImage.path}/${oldImage.name}`);
|
||||
await prisma.fileStorage.delete({
|
||||
where: { id: oldImage.id },
|
||||
})
|
||||
} catch (error) {
|
||||
console.error("Gagal hapus gambar lama:", error);
|
||||
console.error("Gagal hapus gambar lama dari MinIO/DB:", error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user