upd: task divisi
Deskripsi: - tambah file nb: blm selesai No Issues
This commit is contained in:
@@ -255,6 +255,7 @@ model Division {
|
||||
DivisionDocumentShare DivisionDocumentShare[]
|
||||
DivisionCalendar DivisionCalendar[]
|
||||
DivisionCalendarReminder DivisionCalendarReminder[]
|
||||
ContainerFileDivision ContainerFileDivision[]
|
||||
}
|
||||
|
||||
model DivisionMember {
|
||||
@@ -446,6 +447,8 @@ model ContainerImage {
|
||||
|
||||
model ContainerFileDivision {
|
||||
id String @id @default(cuid())
|
||||
Division Division @relation(fields: [idDivision], references: [id])
|
||||
idDivision String
|
||||
name String
|
||||
extension String
|
||||
isActive Boolean @default(true)
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { funGetUserByCookies } from "@/module/auth";
|
||||
import _, { ceil } from "lodash";
|
||||
import moment from "moment";
|
||||
import { NextResponse } from "next/server";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
import moment from "moment";
|
||||
|
||||
|
||||
// GET ALL DATA TUGAS DIVISI
|
||||
@@ -66,7 +68,7 @@ export async function GET(request: Request) {
|
||||
|
||||
const formatData = data.map((v: any) => ({
|
||||
..._.omit(v, ["DivisionProjectTask", "DivisionProjectMember"]),
|
||||
progress: ceil((v.DivisionProjectTask.filter((i: any) => i.status == 1).length*100) / v.DivisionProjectTask.length),
|
||||
progress: ceil((v.DivisionProjectTask.filter((i: any) => i.status == 1).length * 100) / v.DivisionProjectTask.length),
|
||||
member: v.DivisionProjectMember.length
|
||||
}))
|
||||
|
||||
@@ -87,7 +89,12 @@ export async function POST(request: Request) {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||
}
|
||||
|
||||
const { title, task, member, file, idDivision } = (await request.json());
|
||||
|
||||
const body = await request.formData()
|
||||
const dataBody = body.get("data")
|
||||
const cekFile = body.has("file0")
|
||||
|
||||
const { title, task, member, idDivision } = JSON.parse(dataBody as string)
|
||||
|
||||
const cek = await prisma.division.count({
|
||||
where: {
|
||||
@@ -142,31 +149,67 @@ 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()
|
||||
|
||||
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()
|
||||
// console.log(file, file.name)
|
||||
|
||||
const dataFile = {
|
||||
name: fName,
|
||||
extension: fExt,
|
||||
idDivision: idDivision,
|
||||
idProject: data.id,
|
||||
}
|
||||
// const insertToContainer = await prisma.containerFileDivision.create({
|
||||
// data:{
|
||||
// idDivision: idDivision,
|
||||
// name: fName,
|
||||
// extension: String(fExt)
|
||||
// }
|
||||
// })
|
||||
|
||||
fileFix.push(dataFile)
|
||||
})
|
||||
|
||||
const insertFile = await prisma.divisionProjectFile.createMany({
|
||||
data: fileFix
|
||||
})
|
||||
|
||||
}
|
||||
// const dataFile = {
|
||||
// name: fName,
|
||||
// extension: fExt,
|
||||
// idDivision: idDivision,
|
||||
// }
|
||||
|
||||
|
||||
return NextResponse.json({ success: true, message: "Berhasil membuat tugas divisi", }, { status: 200 });
|
||||
// fileFix.push(dataFile)
|
||||
// }
|
||||
// a++
|
||||
// }
|
||||
|
||||
// const insertFile = await prisma.divisionProjectFile.createMany({
|
||||
// data: fileFix
|
||||
// })
|
||||
// }
|
||||
|
||||
|
||||
// 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 = {
|
||||
// name: fName,
|
||||
// extension: fExt,
|
||||
// idDivision: idDivision,
|
||||
// idProject: data.id,
|
||||
// }
|
||||
|
||||
// fileFix.push(dataFile)
|
||||
// })
|
||||
|
||||
// const insertFile = await prisma.divisionProjectFile.createMany({
|
||||
// data: fileFix
|
||||
// })
|
||||
|
||||
// }
|
||||
|
||||
|
||||
return NextResponse.json({ success: true, message: "Berhasil membuat tugas divisi" }, { status: 200 });
|
||||
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
|
||||
@@ -6,16 +6,11 @@ export const funGetAllTask = async (path?: string) => {
|
||||
}
|
||||
|
||||
|
||||
export const funCreateTask = async (data: IFormTaskDivision) => {
|
||||
if (data.title.length < 3)
|
||||
return { success: false, message: 'Nama Kegiatan minimal 3 karakter' }
|
||||
export const funCreateTask = async (data: FormData) => {
|
||||
|
||||
const response = await fetch("/api/task", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
body: data,
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
|
||||
@@ -32,7 +32,8 @@ export default function CreateTask() {
|
||||
const memberValue = member.get() as IFormMemberTask[]
|
||||
const [dataTask, setDataTask] = useState<IFormDateTask[]>([])
|
||||
const openRef = useRef<() => void>(null)
|
||||
const [fileForm, setFileForm] = useState<FormData[]>([])
|
||||
const [fileForm, setFileForm] = useState<any[]>([])
|
||||
const [imgForm, setImgForm] = useState<any>()
|
||||
const [listFile, setListFile] = useState<IListFileTask[]>([])
|
||||
const [indexDelFile, setIndexDelFile] = useState<number>(0)
|
||||
const [indexDelTask, setIndexDelTask] = useState<number>(0)
|
||||
@@ -57,22 +58,27 @@ export default function CreateTask() {
|
||||
|
||||
async function onSubmit() {
|
||||
try {
|
||||
const response = await funCreateTask(
|
||||
{
|
||||
const fd = new FormData();
|
||||
for (let i = 0; i < fileForm.length; i++) {
|
||||
fd.append(`file${i}`, fileForm[i]);
|
||||
}
|
||||
|
||||
fd.append("data", JSON.stringify({
|
||||
idDivision: param.id,
|
||||
title,
|
||||
task: dataTask,
|
||||
file: fileForm,
|
||||
member: memberValue
|
||||
})
|
||||
}))
|
||||
|
||||
const response = await funCreateTask(fd)
|
||||
|
||||
if (response.success) {
|
||||
toast.success(response.message)
|
||||
setTitle("")
|
||||
member.set([])
|
||||
setFileForm([])
|
||||
setListFile([])
|
||||
setDataTask([])
|
||||
// setTitle("")
|
||||
// member.set([])
|
||||
// setFileForm([])
|
||||
// setListFile([])
|
||||
// setDataTask([])
|
||||
} else {
|
||||
toast.error(response.message)
|
||||
}
|
||||
@@ -287,9 +293,7 @@ export default function CreateTask() {
|
||||
onDrop={async (files) => {
|
||||
if (!files || _.isEmpty(files))
|
||||
return toast.error('Tidak ada file yang dipilih')
|
||||
const fd = new FormData();
|
||||
fd.append("file", files[0]);
|
||||
setFileForm([...fileForm, fd])
|
||||
setFileForm([...fileForm, files[0]])
|
||||
setListFile([...listFile, { name: files[0].name, extension: files[0].type.split("/")[1] }])
|
||||
}}
|
||||
activateOnClick={false}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"noEmit": true,
|
||||
"downlevelIteration": true,
|
||||
"esModuleInterop": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "bundler",
|
||||
|
||||
Reference in New Issue
Block a user