upd: document
Deskripsi: - delete document No Issues
This commit is contained in:
@@ -29,6 +29,21 @@ export async function GET(request: Request) {
|
|||||||
return NextResponse.json({ success: false, message: "Gagal mendapatkan divisi, data tidak ditemukan" }, { status: 404 });
|
return NextResponse.json({ success: false, message: "Gagal mendapatkan divisi, data tidak ditemukan" }, { status: 404 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (path != "home" && path != "null" && path != "undefined" && path != "") {
|
||||||
|
const cekPath = await prisma.divisionDocumentFolderFile.count({
|
||||||
|
where: {
|
||||||
|
isActive: true,
|
||||||
|
id: String(path)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (cekPath == 0) {
|
||||||
|
return NextResponse.json({ success: false, message: "Gagal mendapatkan item, data tidak ditemukan" }, { status: 404 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const data = await prisma.divisionDocumentFolderFile.findMany({
|
const data = await prisma.divisionDocumentFolderFile.findMany({
|
||||||
where: {
|
where: {
|
||||||
@@ -63,11 +78,11 @@ export async function GET(request: Request) {
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
|
|
||||||
return NextResponse.json({ success: true, message: "Berhasil mendapatkan divisi", data: allData, }, { status: 200 });
|
return NextResponse.json({ success: true, message: "Berhasil mendapatkan item", data: allData, }, { status: 200 });
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
return NextResponse.json({ success: false, message: "Gagal mendapatkan divisi, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
|
return NextResponse.json({ success: false, message: "Gagal mendapatkan item, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,6 +157,7 @@ export async function POST(request: Request) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// RENAME ITEM
|
||||||
export async function PUT(request: Request) {
|
export async function PUT(request: Request) {
|
||||||
try {
|
try {
|
||||||
const user = await funGetUserByCookies()
|
const user = await funGetUserByCookies()
|
||||||
@@ -195,4 +211,35 @@ export async function PUT(request: Request) {
|
|||||||
console.log(error);
|
console.log(error);
|
||||||
return NextResponse.json({ success: false, message: "Gagal mengubah nama item, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
|
return NextResponse.json({ success: false, message: "Gagal mengubah nama item, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// DELETE ITEM
|
||||||
|
export async function DELETE(request: Request) {
|
||||||
|
try {
|
||||||
|
const user = await funGetUserByCookies()
|
||||||
|
if (user.id == undefined) {
|
||||||
|
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await request.json()
|
||||||
|
|
||||||
|
for (let i = 0; i < data.length; i++) {
|
||||||
|
const id = data[i].id;
|
||||||
|
const cekFile = await prisma.divisionDocumentFolderFile.update({
|
||||||
|
where: {
|
||||||
|
id: id
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
isActive: false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return NextResponse.json({ success: true, message: "Berhasil menghapus item" }, { status: 200 });
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
return NextResponse.json({ success: false, message: "Gagal menghapus item, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
|
||||||
|
}
|
||||||
};
|
};
|
||||||
@@ -32,4 +32,15 @@ export const funRenameDocument = async (data: IFormEditItem) => {
|
|||||||
body: JSON.stringify(data),
|
body: JSON.stringify(data),
|
||||||
});
|
});
|
||||||
return await response.json().catch(() => null);
|
return await response.json().catch(() => null);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const funDeleteDocument = async (data: []) => {
|
||||||
|
const response = await fetch("/api/document", {
|
||||||
|
method: "DELETE",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
});
|
||||||
|
return await response.json().catch(() => null);
|
||||||
};
|
};
|
||||||
@@ -16,7 +16,7 @@ import DrawerMenuDocumentDivision from './drawer_menu_document_division';
|
|||||||
import DrawerMore from './drawer_more';
|
import DrawerMore from './drawer_more';
|
||||||
import { funGetDivisionById } from '@/module/division_new';
|
import { funGetDivisionById } from '@/module/division_new';
|
||||||
import { useShallowEffect } from '@mantine/hooks';
|
import { useShallowEffect } from '@mantine/hooks';
|
||||||
import { funGetAllDocument, funRenameDocument } from '../lib/api_document';
|
import { funDeleteDocument, funGetAllDocument, funRenameDocument } from '../lib/api_document';
|
||||||
import { IDataDocument } from '../lib/type_document';
|
import { IDataDocument } from '../lib/type_document';
|
||||||
import { useHookstate } from '@hookstate/core';
|
import { useHookstate } from '@hookstate/core';
|
||||||
import { globalRefreshDocument } from '../lib/val_document';
|
import { globalRefreshDocument } from '../lib/val_document';
|
||||||
@@ -100,12 +100,28 @@ export default function NavbarDocumentDivision() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function onTrue(val: boolean) {
|
async function onConfirmDelete(val: boolean) {
|
||||||
if (val) {
|
if (val) {
|
||||||
toast.success("Sukses! Data dihapus");
|
try {
|
||||||
|
const respon = await funDeleteDocument(selectedFiles)
|
||||||
|
if (respon.success) {
|
||||||
|
getOneData()
|
||||||
|
} else {
|
||||||
|
toast.error(respon.message)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error)
|
||||||
|
toast.error("Gagal menghapus item, coba lagi nanti")
|
||||||
|
}
|
||||||
|
|
||||||
|
handleBatal()
|
||||||
}
|
}
|
||||||
|
|
||||||
setIsDelete(false)
|
setIsDelete(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async function onRenameSubmit() {
|
async function onRenameSubmit() {
|
||||||
try {
|
try {
|
||||||
const res = await funRenameDocument(bodyRename)
|
const res = await funRenameDocument(bodyRename)
|
||||||
@@ -238,6 +254,8 @@ export default function NavbarDocumentDivision() {
|
|||||||
</ActionIcon>
|
</ActionIcon>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
||||||
<Box>
|
<Box>
|
||||||
<Box p={20} pb={60}>
|
<Box p={20} pb={60}>
|
||||||
{dataDocument.map((v, i) => {
|
{dataDocument.map((v, i) => {
|
||||||
@@ -295,11 +313,18 @@ export default function NavbarDocumentDivision() {
|
|||||||
</LayoutDrawer>
|
</LayoutDrawer>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{/* MODAL KONFIRMASI DELETE */}
|
||||||
<LayoutModal opened={isDelete} onClose={() => setIsDelete(false)}
|
<LayoutModal opened={isDelete} onClose={() => setIsDelete(false)}
|
||||||
description="Apakah Anda yakin ingin menghapus data?"
|
description="Apakah Anda yakin ingin menghapus item?"
|
||||||
onYes={(val) => { onTrue(val) }} />
|
onYes={(val) => {
|
||||||
|
onConfirmDelete(val)
|
||||||
|
}} />
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{/* MODAL RENAME */}
|
||||||
<Modal styles={{
|
<Modal styles={{
|
||||||
body: {
|
body: {
|
||||||
borderRadius: 20
|
borderRadius: 20
|
||||||
|
|||||||
Reference in New Issue
Block a user