upd: task
Deskripsi: - update status task - progress task No Issues
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import { prisma } from "@/module/_global";
|
import { prisma } from "@/module/_global";
|
||||||
import { funGetUserByCookies } from "@/module/auth";
|
import { funGetUserByCookies } from "@/module/auth";
|
||||||
|
import _ from "lodash";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
@@ -62,7 +63,7 @@ export async function PUT(request: Request, context: { params: { id: string } })
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { id } = context.params;
|
const { id } = context.params;
|
||||||
const { status } = (await request.json());
|
const { status, idProject } = (await request.json());
|
||||||
const data = await prisma.divisionProjectTask.count({
|
const data = await prisma.divisionProjectTask.count({
|
||||||
where: {
|
where: {
|
||||||
id: id,
|
id: id,
|
||||||
@@ -88,6 +89,34 @@ export async function PUT(request: Request, context: { params: { id: string } })
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// const cek progress
|
||||||
|
const dataTask = await prisma.divisionProjectTask.findMany({
|
||||||
|
where: {
|
||||||
|
isActive: true,
|
||||||
|
idProject: idProject
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const semua = dataTask.length
|
||||||
|
const selesai = _.filter(dataTask, { status: 1 }).length
|
||||||
|
const progress = Math.ceil((selesai / semua) * 100)
|
||||||
|
let statusProject = 1
|
||||||
|
|
||||||
|
if (progress == 100) {
|
||||||
|
statusProject = 2
|
||||||
|
} else if (progress == 0) {
|
||||||
|
statusProject = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
const updProject = await prisma.divisionProject.update({
|
||||||
|
where: {
|
||||||
|
id: idProject
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
status: statusProject
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
success: true,
|
success: true,
|
||||||
|
|||||||
@@ -49,7 +49,8 @@ export async function GET(request: Request) {
|
|||||||
isActive: true
|
isActive: true
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
title: true
|
title: true,
|
||||||
|
status: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
DivisionProjectMember: {
|
DivisionProjectMember: {
|
||||||
@@ -65,7 +66,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 / 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
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ export const funDeleteDetailTask = async (path: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export const funUpdateStatusDetailTask = async (path: string, data: { status: number }) => {
|
export const funUpdateStatusDetailTask = async (path: string, data: { status: number, idProject: string }) => {
|
||||||
const response = await fetch(`/api/task/detail/${path}`, {
|
const response = await fetch(`/api/task/detail/${path}`, {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ export default function ListTugasDetailTask() {
|
|||||||
|
|
||||||
async function onUpdateStatus(val: number) {
|
async function onUpdateStatus(val: number) {
|
||||||
try {
|
try {
|
||||||
const res = await funUpdateStatusDetailTask(idData, { status: val });
|
const res = await funUpdateStatusDetailTask(idData, { status: val, idProject: param.detail });
|
||||||
if (res.success) {
|
if (res.success) {
|
||||||
toast.success(res.message);
|
toast.success(res.message);
|
||||||
refresh.set(true)
|
refresh.set(true)
|
||||||
|
|||||||
@@ -176,8 +176,8 @@ export default function ListDivisionTask() {
|
|||||||
</Card.Section>
|
</Card.Section>
|
||||||
<Box pt={10}>
|
<Box pt={10}>
|
||||||
<Progress.Root size="xl" radius="xl" style={{ border: `1px solid ${'#BDBDBD'}` }}>
|
<Progress.Root size="xl" radius="xl" style={{ border: `1px solid ${'#BDBDBD'}` }}>
|
||||||
<Progress.Section value={v.status} color="yellow" striped >
|
<Progress.Section value={v.progress} color="yellow" striped >
|
||||||
<Progress.Label>{v.status}%</Progress.Label>
|
<Progress.Label>{v.progress}%</Progress.Label>
|
||||||
</Progress.Section>
|
</Progress.Section>
|
||||||
</Progress.Root>
|
</Progress.Root>
|
||||||
<Text my={10}>{v.desc}</Text>
|
<Text my={10}>{v.desc}</Text>
|
||||||
|
|||||||
Reference in New Issue
Block a user