upd: create task divisi
Deskripsi: - tambah file No Issues
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -39,4 +39,5 @@ yarn-error.log*
|
||||
next-env.d.ts
|
||||
|
||||
# folder foto kandidat
|
||||
/public/image/
|
||||
/public/image/
|
||||
/public/file/
|
||||
@@ -2,8 +2,8 @@ import { CreateTask, FileSave } from "@/module/task";
|
||||
|
||||
function Page({ searchParams }: { searchParams: any }) {
|
||||
|
||||
if (searchParams.page == "file-save")
|
||||
return <FileSave kategori="task" />
|
||||
// if (searchParams.page == "file-save")
|
||||
// return <FileSave kategori="task" />
|
||||
|
||||
return <CreateTask />
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ export async function POST(request: Request) {
|
||||
|
||||
if (member.length > 0) {
|
||||
const dataMember = member.map((v: any) => ({
|
||||
..._.omit(v, ["idUser", "name"]),
|
||||
..._.omit(v, ["idUser", "name", "img"]),
|
||||
idDivision: idDivision,
|
||||
idProject: data.id,
|
||||
idUser: v.idUser,
|
||||
@@ -147,66 +147,56 @@ export async function POST(request: Request) {
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
let fileFix: any[] = []
|
||||
|
||||
// if (cekFile) {
|
||||
// let a = 0
|
||||
// const root = path.join(process.cwd(), "./public/image/user/");
|
||||
// for (var pair of body.entries()) {
|
||||
// if (String(pair[0]) == "file" + a) {
|
||||
// const file = body.get(pair[0]) as File
|
||||
// const fName = file.name
|
||||
// const fExt = fName.split(".").pop()
|
||||
|
||||
// console.log(file, file.name)
|
||||
|
||||
// const insertToContainer = await prisma.containerFileDivision.create({
|
||||
// data:{
|
||||
// idDivision: idDivision,
|
||||
// name: fName,
|
||||
// extension: String(fExt)
|
||||
// }
|
||||
// })
|
||||
|
||||
// const dataFile = {
|
||||
// name: fName,
|
||||
// extension: fExt,
|
||||
// idDivision: idDivision,
|
||||
// }
|
||||
if (cekFile) {
|
||||
let a = 0
|
||||
const root = path.join(process.cwd(), "./public/file/task/");
|
||||
for (var pair of body.entries()) {
|
||||
if (String(pair[0]) == "file" + a) {
|
||||
const file = body.get(pair[0]) as File
|
||||
const fName = file.name.split(".")[0]
|
||||
const fExt = file.name.split(".").pop()
|
||||
|
||||
|
||||
// fileFix.push(dataFile)
|
||||
// }
|
||||
// a++
|
||||
// }
|
||||
const insertToContainer = await prisma.containerFileDivision.create({
|
||||
data: {
|
||||
idDivision: idDivision,
|
||||
name: fName,
|
||||
extension: String(fExt)
|
||||
},
|
||||
select: {
|
||||
id: true
|
||||
}
|
||||
})
|
||||
|
||||
// const insertFile = await prisma.divisionProjectFile.createMany({
|
||||
// data: fileFix
|
||||
// })
|
||||
// }
|
||||
const nameFix = insertToContainer.id + '.' + fExt
|
||||
const filePath = path.join(root, nameFix)
|
||||
// Konversi ArrayBuffer ke Buffer
|
||||
const buffer = Buffer.from(await file.arrayBuffer());
|
||||
// Tulis file ke sistem
|
||||
fs.writeFileSync(filePath, buffer);
|
||||
|
||||
|
||||
// if (file.length > 0) {
|
||||
// file.map((v: any, index: any) => {
|
||||
// const f: any = file[index].get('file')
|
||||
// const fName = f.name
|
||||
// const fExt = fName.split(".").pop()
|
||||
const dataFile = {
|
||||
idProject: data.id,
|
||||
idDivision: idDivision,
|
||||
idFile: insertToContainer.id,
|
||||
createdBy: user.id,
|
||||
}
|
||||
|
||||
// const dataFile = {
|
||||
// name: fName,
|
||||
// extension: fExt,
|
||||
// idDivision: idDivision,
|
||||
// idProject: data.id,
|
||||
// }
|
||||
|
||||
// fileFix.push(dataFile)
|
||||
// })
|
||||
fileFix.push(dataFile)
|
||||
}
|
||||
a++
|
||||
}
|
||||
|
||||
// const insertFile = await prisma.divisionProjectFile.createMany({
|
||||
// data: fileFix
|
||||
// })
|
||||
|
||||
// }
|
||||
const insertFile = await prisma.divisionProjectFile.createMany({
|
||||
data: fileFix
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
return NextResponse.json({ success: true, message: "Berhasil membuat tugas divisi" }, { status: 200 });
|
||||
|
||||
@@ -74,11 +74,11 @@ export default function CreateTask() {
|
||||
|
||||
if (response.success) {
|
||||
toast.success(response.message)
|
||||
// setTitle("")
|
||||
// member.set([])
|
||||
// setFileForm([])
|
||||
// setListFile([])
|
||||
// setDataTask([])
|
||||
setTitle("")
|
||||
member.set([])
|
||||
setFileForm([])
|
||||
setListFile([])
|
||||
setDataTask([])
|
||||
} else {
|
||||
toast.error(response.message)
|
||||
}
|
||||
@@ -322,7 +322,7 @@ export default function CreateTask() {
|
||||
<Text ta={"center"}>diperangkat</Text>
|
||||
</Box>
|
||||
</Dropzone>
|
||||
<Box onClick={() => router.push("/task/create?page=file-save")}>
|
||||
{/* <Box onClick={() => router.push("/task/create?page=file-save")}>
|
||||
<Box
|
||||
bg={"#DCEED8"}
|
||||
style={{
|
||||
@@ -339,7 +339,7 @@ export default function CreateTask() {
|
||||
Pilih file yang
|
||||
</Text>
|
||||
<Text ta={"center"}>sudah ada</Text>
|
||||
</Box>
|
||||
</Box> */}
|
||||
</Flex>
|
||||
</LayoutDrawer>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user