upd: task divisi
Deskripsi: - tambah file nb: blm selesai No Issues
This commit is contained in:
@@ -255,6 +255,7 @@ model Division {
|
|||||||
DivisionDocumentShare DivisionDocumentShare[]
|
DivisionDocumentShare DivisionDocumentShare[]
|
||||||
DivisionCalendar DivisionCalendar[]
|
DivisionCalendar DivisionCalendar[]
|
||||||
DivisionCalendarReminder DivisionCalendarReminder[]
|
DivisionCalendarReminder DivisionCalendarReminder[]
|
||||||
|
ContainerFileDivision ContainerFileDivision[]
|
||||||
}
|
}
|
||||||
|
|
||||||
model DivisionMember {
|
model DivisionMember {
|
||||||
@@ -446,6 +447,8 @@ model ContainerImage {
|
|||||||
|
|
||||||
model ContainerFileDivision {
|
model ContainerFileDivision {
|
||||||
id String @id @default(cuid())
|
id String @id @default(cuid())
|
||||||
|
Division Division @relation(fields: [idDivision], references: [id])
|
||||||
|
idDivision String
|
||||||
name String
|
name String
|
||||||
extension String
|
extension String
|
||||||
isActive Boolean @default(true)
|
isActive Boolean @default(true)
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import { prisma } from "@/module/_global";
|
import { prisma } from "@/module/_global";
|
||||||
import { funGetUserByCookies } from "@/module/auth";
|
import { funGetUserByCookies } from "@/module/auth";
|
||||||
import _, { ceil } from "lodash";
|
import _, { ceil } from "lodash";
|
||||||
import moment from "moment";
|
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
|
import path from "path";
|
||||||
|
import fs from "fs";
|
||||||
|
import moment from "moment";
|
||||||
|
|
||||||
|
|
||||||
// GET ALL DATA TUGAS DIVISI
|
// GET ALL DATA TUGAS DIVISI
|
||||||
@@ -66,7 +68,7 @@ export async function GET(request: Request) {
|
|||||||
|
|
||||||
const formatData = data.map((v: any) => ({
|
const formatData = data.map((v: any) => ({
|
||||||
..._.omit(v, ["DivisionProjectTask", "DivisionProjectMember"]),
|
..._.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
|
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 });
|
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({
|
const cek = await prisma.division.count({
|
||||||
where: {
|
where: {
|
||||||
@@ -142,31 +149,67 @@ export async function POST(request: Request) {
|
|||||||
|
|
||||||
let fileFix: any[] = []
|
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) {
|
// console.log(file, file.name)
|
||||||
file.map((v: any, index: any) => {
|
|
||||||
const f: any = file[index].get('file')
|
|
||||||
const fName = f.name
|
|
||||||
const fExt = fName.split(".").pop()
|
|
||||||
|
|
||||||
const dataFile = {
|
// const insertToContainer = await prisma.containerFileDivision.create({
|
||||||
name: fName,
|
// data:{
|
||||||
extension: fExt,
|
// idDivision: idDivision,
|
||||||
idDivision: idDivision,
|
// name: fName,
|
||||||
idProject: data.id,
|
// extension: String(fExt)
|
||||||
}
|
// }
|
||||||
|
// })
|
||||||
|
|
||||||
fileFix.push(dataFile)
|
// const dataFile = {
|
||||||
})
|
// name: fName,
|
||||||
|
// extension: fExt,
|
||||||
const insertFile = await prisma.divisionProjectFile.createMany({
|
// idDivision: idDivision,
|
||||||
data: fileFix
|
// }
|
||||||
})
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
|||||||
@@ -6,16 +6,11 @@ export const funGetAllTask = async (path?: string) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export const funCreateTask = async (data: IFormTaskDivision) => {
|
export const funCreateTask = async (data: FormData) => {
|
||||||
if (data.title.length < 3)
|
|
||||||
return { success: false, message: 'Nama Kegiatan minimal 3 karakter' }
|
|
||||||
|
|
||||||
const response = await fetch("/api/task", {
|
const response = await fetch("/api/task", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
body: data,
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
body: JSON.stringify(data),
|
|
||||||
});
|
});
|
||||||
return await response.json().catch(() => null);
|
return await response.json().catch(() => null);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -32,7 +32,8 @@ export default function CreateTask() {
|
|||||||
const memberValue = member.get() as IFormMemberTask[]
|
const memberValue = member.get() as IFormMemberTask[]
|
||||||
const [dataTask, setDataTask] = useState<IFormDateTask[]>([])
|
const [dataTask, setDataTask] = useState<IFormDateTask[]>([])
|
||||||
const openRef = useRef<() => void>(null)
|
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 [listFile, setListFile] = useState<IListFileTask[]>([])
|
||||||
const [indexDelFile, setIndexDelFile] = useState<number>(0)
|
const [indexDelFile, setIndexDelFile] = useState<number>(0)
|
||||||
const [indexDelTask, setIndexDelTask] = useState<number>(0)
|
const [indexDelTask, setIndexDelTask] = useState<number>(0)
|
||||||
@@ -57,22 +58,27 @@ export default function CreateTask() {
|
|||||||
|
|
||||||
async function onSubmit() {
|
async function onSubmit() {
|
||||||
try {
|
try {
|
||||||
const response = await funCreateTask(
|
const fd = new FormData();
|
||||||
{
|
for (let i = 0; i < fileForm.length; i++) {
|
||||||
idDivision: param.id,
|
fd.append(`file${i}`, fileForm[i]);
|
||||||
title,
|
}
|
||||||
task: dataTask,
|
|
||||||
file: fileForm,
|
fd.append("data", JSON.stringify({
|
||||||
member: memberValue
|
idDivision: param.id,
|
||||||
})
|
title,
|
||||||
|
task: dataTask,
|
||||||
|
member: memberValue
|
||||||
|
}))
|
||||||
|
|
||||||
|
const response = await funCreateTask(fd)
|
||||||
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
@@ -250,28 +256,28 @@ export default function CreateTask() {
|
|||||||
|
|
||||||
|
|
||||||
</Box>
|
</Box>
|
||||||
<Box pos={'fixed'} bottom={0} p={rem(20)} w={"100%"} style={{
|
<Box pos={'fixed'} bottom={0} p={rem(20)} w={"100%"} style={{
|
||||||
maxWidth: rem(550),
|
maxWidth: rem(550),
|
||||||
zIndex: 999,
|
zIndex: 999,
|
||||||
backgroundColor: `${WARNA.bgWhite}`,
|
backgroundColor: `${WARNA.bgWhite}`,
|
||||||
}}>
|
}}>
|
||||||
<Button
|
<Button
|
||||||
color="white"
|
color="white"
|
||||||
bg={WARNA.biruTua}
|
bg={WARNA.biruTua}
|
||||||
size="lg" radius={30}
|
size="lg" radius={30}
|
||||||
fullWidth
|
fullWidth
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (
|
if (
|
||||||
title !== ""
|
title !== ""
|
||||||
) {
|
) {
|
||||||
setOpenModal(true)
|
setOpenModal(true)
|
||||||
} else {
|
} else {
|
||||||
toast.error("Semua form harus diisi")
|
toast.error("Semua form harus diisi")
|
||||||
}
|
}
|
||||||
}}>
|
}}>
|
||||||
Simpan
|
Simpan
|
||||||
</Button>
|
</Button>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -287,9 +293,7 @@ export default function CreateTask() {
|
|||||||
onDrop={async (files) => {
|
onDrop={async (files) => {
|
||||||
if (!files || _.isEmpty(files))
|
if (!files || _.isEmpty(files))
|
||||||
return toast.error('Tidak ada file yang dipilih')
|
return toast.error('Tidak ada file yang dipilih')
|
||||||
const fd = new FormData();
|
setFileForm([...fileForm, files[0]])
|
||||||
fd.append("file", files[0]);
|
|
||||||
setFileForm([...fileForm, fd])
|
|
||||||
setListFile([...listFile, { name: files[0].name, extension: files[0].type.split("/")[1] }])
|
setListFile([...listFile, { name: files[0].name, extension: files[0].type.split("/")[1] }])
|
||||||
}}
|
}}
|
||||||
activateOnClick={false}
|
activateOnClick={false}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"noEmit": true,
|
"noEmit": true,
|
||||||
|
"downlevelIteration": true,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"module": "esnext",
|
"module": "esnext",
|
||||||
"moduleResolution": "bundler",
|
"moduleResolution": "bundler",
|
||||||
|
|||||||
Reference in New Issue
Block a user