upd: dokumen
Deskripsi: - copy file No Issues
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { prisma } from "@/module/_global";
|
import { DIR, funCopyFile, prisma } from "@/module/_global";
|
||||||
import { funGetUserByCookies } from "@/module/auth";
|
import { funGetUserByCookies } from "@/module/auth";
|
||||||
import { createLogUser } from "@/module/user";
|
import { createLogUser } from "@/module/user";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
@@ -106,85 +106,55 @@ export async function PUT(request: Request) {
|
|||||||
let name = dataItem[i].name;
|
let name = dataItem[i].name;
|
||||||
const category = dataItem[i].category;
|
const category = dataItem[i].category;
|
||||||
const extension = dataItem[i].extension;
|
const extension = dataItem[i].extension;
|
||||||
|
const idStorage = dataItem[i].idStorage;
|
||||||
|
|
||||||
let status = false
|
const copyOnStorage = await funCopyFile({ fileId: idStorage, dirId: DIR.document })
|
||||||
let numb = 1
|
if (copyOnStorage.success) {
|
||||||
do {
|
let status = false
|
||||||
const cekName = await prisma.divisionDocumentFolderFile.count({
|
let numb = 1
|
||||||
where: {
|
do {
|
||||||
path: path,
|
const cekName = await prisma.divisionDocumentFolderFile.count({
|
||||||
isActive: true,
|
where: {
|
||||||
|
path: path,
|
||||||
|
isActive: true,
|
||||||
|
extension,
|
||||||
|
name
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (cekName > 0) {
|
||||||
|
name = dataItem[i].name + " (" + numb + ")"
|
||||||
|
numb++
|
||||||
|
status = false
|
||||||
|
} else {
|
||||||
|
status = true
|
||||||
|
}
|
||||||
|
} while (status == false);
|
||||||
|
|
||||||
|
|
||||||
|
const create = await prisma.divisionDocumentFolderFile.create({
|
||||||
|
data: {
|
||||||
|
name,
|
||||||
|
path,
|
||||||
|
idDivision,
|
||||||
|
category,
|
||||||
extension,
|
extension,
|
||||||
name
|
idStorage: copyOnStorage.data.id,
|
||||||
|
createdBy: user.id
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if (cekName > 0) {
|
// create log user
|
||||||
name = dataItem[i].name + " (" + numb + ")"
|
const log = await createLogUser({ act: 'CREATE', desc: 'User menyalin file', table: 'divisionDocumentFolderFile', data: create.id })
|
||||||
numb++
|
}
|
||||||
status = false
|
|
||||||
} else {
|
|
||||||
status = true
|
|
||||||
}
|
|
||||||
} while (status == false);
|
|
||||||
|
|
||||||
|
|
||||||
const create = await prisma.divisionDocumentFolderFile.create({
|
|
||||||
data: {
|
|
||||||
name,
|
|
||||||
path,
|
|
||||||
idDivision,
|
|
||||||
category,
|
|
||||||
extension,
|
|
||||||
createdBy: user.id
|
|
||||||
},
|
|
||||||
select: {
|
|
||||||
id: true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// let newPath = create.id
|
|
||||||
// let idPath = dataItem[i].id;
|
|
||||||
// let statusCek = false
|
|
||||||
// do {
|
|
||||||
// const cekFolder = await prisma.divisionDocumentFolderFile.findMany({
|
|
||||||
// where: {
|
|
||||||
// isActive: true,
|
|
||||||
// path: idPath
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
|
|
||||||
// if (cekFolder.length == 0) {
|
|
||||||
// statusCek = true
|
|
||||||
// } else {
|
|
||||||
// for (let index = 0; index < cekFolder.length; index++) {
|
|
||||||
// const addChildren = await prisma.divisionDocumentFolderFile.create({
|
|
||||||
// data: {
|
|
||||||
// name: cekFolder[index].name,
|
|
||||||
// path: newPath,
|
|
||||||
// idDivision,
|
|
||||||
// category: cekFolder[index].category,
|
|
||||||
// extension: cekFolder[index].extension,
|
|
||||||
// createdBy: user.id
|
|
||||||
// },
|
|
||||||
// select: {
|
|
||||||
// id: true
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
|
|
||||||
// newPath = create.id
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
// } while (statusCek == false);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return NextResponse.json({ success: true, message: "Berhasil salin item" }, { status: 200 });
|
return NextResponse.json({ success: true, message: "Berhasil salin item" }, { status: 200 });
|
||||||
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
return NextResponse.json({ success: false, message: "Gagal salin item, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
|
return NextResponse.json({ success: false, message: "Gagal salin item, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
|
||||||
@@ -222,7 +192,8 @@ export async function DELETE(request: Request) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// create log user
|
||||||
|
const log = await createLogUser({ act: 'CREATE', desc: 'User membagikan item', table: 'divisionDocumentShare', data: '' })
|
||||||
return NextResponse.json({ success: true, message: "Berhasil membagikan item" }, { status: 200 });
|
return NextResponse.json({ success: true, message: "Berhasil membagikan item" }, { status: 200 });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|||||||
22
src/module/_global/fun/copy_file.ts
Normal file
22
src/module/_global/fun/copy_file.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
export async function funCopyFile({ fileId, dirId }: { fileId: string, dirId: string }) {
|
||||||
|
try {
|
||||||
|
const res = await fetch(`https://wibu-storage.wibudev.com/api/files/copy/${dirId}/${dirId}`, {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify({ fileId: fileId }),
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${process.env.WS_APIKEY}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (res.ok) {
|
||||||
|
const hasil = await res.json()
|
||||||
|
return { success: true, data: hasil.data }
|
||||||
|
} else {
|
||||||
|
const errorText = await res.json();
|
||||||
|
return { success: false, data: {} }
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Copy error:", error);
|
||||||
|
return { success: false, data: {} }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import SkeletonDetailListTugasTask from "./components/skeleton_detail_list_tugas
|
|||||||
import SkeletonDetailProfile from "./components/skeleton_detail_profile";
|
import SkeletonDetailProfile from "./components/skeleton_detail_profile";
|
||||||
import SkeletonSingle from "./components/skeleton_single";
|
import SkeletonSingle from "./components/skeleton_single";
|
||||||
import WrapLayout from "./components/wrap_layout";
|
import WrapLayout from "./components/wrap_layout";
|
||||||
|
import { funCopyFile } from "./fun/copy_file";
|
||||||
import { funDeleteFile } from "./fun/delete_file";
|
import { funDeleteFile } from "./fun/delete_file";
|
||||||
import { funUploadFile } from "./fun/upload_file";
|
import { funUploadFile } from "./fun/upload_file";
|
||||||
import { WARNA } from "./fun/WARNA";
|
import { WARNA } from "./fun/WARNA";
|
||||||
@@ -42,3 +43,4 @@ export { funUploadFile }
|
|||||||
export { funDeleteFile }
|
export { funDeleteFile }
|
||||||
export { DIR }
|
export { DIR }
|
||||||
export { TEMA }
|
export { TEMA }
|
||||||
|
export { funCopyFile }
|
||||||
|
|||||||
@@ -9,12 +9,14 @@ import { funCopyDocument, funMoveDocument } from "../lib/api_document";
|
|||||||
import { useHookstate } from "@hookstate/core";
|
import { useHookstate } from "@hookstate/core";
|
||||||
import { globalRefreshDocument } from "../lib/val_document";
|
import { globalRefreshDocument } from "../lib/val_document";
|
||||||
import { useParams } from "next/navigation";
|
import { useParams } from "next/navigation";
|
||||||
|
import { useShallowEffect } from "@mantine/hooks";
|
||||||
|
|
||||||
export default function DrawerMore({ data }: { data: IDataDocument[] }) {
|
export default function DrawerMore({ data }: { data: IDataDocument[] }) {
|
||||||
const [isCut, setIsCut] = useState(false)
|
const [isCut, setIsCut] = useState(false)
|
||||||
const [isCopy, setIsCopy] = useState(false)
|
const [isCopy, setIsCopy] = useState(false)
|
||||||
const refresh = useHookstate(globalRefreshDocument)
|
const refresh = useHookstate(globalRefreshDocument)
|
||||||
const param = useParams<{ id: string }>()
|
const param = useParams<{ id: string }>()
|
||||||
|
const [forbidCopy, setForbidCopy] = useState(true)
|
||||||
|
|
||||||
|
|
||||||
async function onMoveItem(path: string) {
|
async function onMoveItem(path: string) {
|
||||||
@@ -51,6 +53,16 @@ export default function DrawerMore({ data }: { data: IDataDocument[] }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function cekFileSelected() {
|
||||||
|
const cek = data.some((i: any) => i.category == "FOLDER")
|
||||||
|
setForbidCopy(cek)
|
||||||
|
}
|
||||||
|
|
||||||
|
useShallowEffect(() => {
|
||||||
|
cekFileSelected()
|
||||||
|
}, [data])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
@@ -66,14 +78,17 @@ export default function DrawerMore({ data }: { data: IDataDocument[] }) {
|
|||||||
<Text c={WARNA.biruTua}>Pindah</Text>
|
<Text c={WARNA.biruTua}>Pindah</Text>
|
||||||
</Box>
|
</Box>
|
||||||
</Flex>
|
</Flex>
|
||||||
<Flex onClick={() => setIsCopy(true)} justify={'center'} align={'center'} direction={'column'} >
|
{
|
||||||
<Box>
|
(!forbidCopy) &&
|
||||||
<LuFolders size={30} color={WARNA.biruTua} />
|
<Flex onClick={() => setIsCopy(true)} justify={'center'} align={'center'} direction={'column'} >
|
||||||
</Box>
|
<Box>
|
||||||
<Box>
|
<LuFolders size={30} color={WARNA.biruTua} />
|
||||||
<Text c={WARNA.biruTua}>Salin</Text>
|
</Box>
|
||||||
</Box>
|
<Box>
|
||||||
</Flex>
|
<Text c={WARNA.biruTua}>Salin</Text>
|
||||||
|
</Box>
|
||||||
|
</Flex>
|
||||||
|
}
|
||||||
</SimpleGrid>
|
</SimpleGrid>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ export default function NavbarDocumentDivision() {
|
|||||||
const [selectedFiles, setSelectedFiles] = useState<any>([])
|
const [selectedFiles, setSelectedFiles] = useState<any>([])
|
||||||
const [selectAll, setSelectAll] = useState(false)
|
const [selectAll, setSelectAll] = useState(false)
|
||||||
const [dariSelectAll, setDariSelectAll] = useState(false)
|
const [dariSelectAll, setDariSelectAll] = useState(false)
|
||||||
const isMobile = useMediaQuery('(max-width: 369px)');
|
const isMobile = useMediaQuery('(max-width: 369px)');
|
||||||
const [bodyRename, setBodyRename] = useState({
|
const [bodyRename, setBodyRename] = useState({
|
||||||
id: '',
|
id: '',
|
||||||
name: '',
|
name: '',
|
||||||
@@ -69,6 +69,7 @@ export default function NavbarDocumentDivision() {
|
|||||||
extension: dataDocument[index].extension,
|
extension: dataDocument[index].extension,
|
||||||
category: dataDocument[index].category,
|
category: dataDocument[index].category,
|
||||||
share: dataDocument[index].share,
|
share: dataDocument[index].share,
|
||||||
|
idStorage: dataDocument[index].idStorage
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
@@ -102,6 +103,7 @@ export default function NavbarDocumentDivision() {
|
|||||||
extension: dataDocument[index].extension,
|
extension: dataDocument[index].extension,
|
||||||
category: dataDocument[index].category,
|
category: dataDocument[index].category,
|
||||||
share: dataDocument[index].share,
|
share: dataDocument[index].share,
|
||||||
|
idStorage: dataDocument[index].idStorage
|
||||||
}
|
}
|
||||||
setSelectedFiles((selectedFiles: any) => [...selectedFiles, newArr])
|
setSelectedFiles((selectedFiles: any) => [...selectedFiles, newArr])
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user