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