upd: tambah anggota task

Deskripsi:
-tambah anggota task

NO ISsues
This commit is contained in:
amel
2024-08-19 16:11:20 +08:00
parent 5e591c6908
commit 912f4fd309
10 changed files with 303 additions and 8 deletions

View File

@@ -0,0 +1,9 @@
import { AddMemberDetailTask } from "@/module/task"
function Page() {
return (
<AddMemberDetailTask />
)
}
export default Page

View File

@@ -0,0 +1,61 @@
import { prisma } from "@/module/_global";
import { funGetUserByCookies } from "@/module/auth";
import _ from "lodash";
import moment from "moment";
import { NextResponse } from "next/server";
// ADD MEMBER TASK DIVISI
export async function POST(request: Request, context: { params: { id: string } }) {
try {
const user = await funGetUserByCookies()
if (user.id == undefined) {
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
}
const { id } = context.params;
const { member, idDivision } = (await request.json());
const data = await prisma.divisionProject.count({
where: {
id: id,
},
});
console.log(member, idDivision)
if (data == 0) {
return NextResponse.json(
{
success: false,
message: "Tambah anggota tugas gagal, data tugas tidak ditemukan",
},
{ status: 404 }
);
}
if (member.length > 0) {
const dataMember = member.map((v: any) => ({
..._.omit(v, ["idUser", "name"]),
idDivision: idDivision,
idProject: id,
idUser: v.idUser,
}))
const insertMember = await prisma.divisionProjectMember.createMany({
data: dataMember
})
}
return NextResponse.json(
{
success: true,
message: "Berhasil menambahkan anggota tugas",
},
{ status: 200 }
);
} catch (error) {
console.log(error);
return NextResponse.json({ success: false, message: "Gagal menambah anggota tugas, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
}
}

View File

@@ -108,6 +108,7 @@ export async function GET(request: Request, context: { params: { id: string } })
},
select: {
id: true,
idUser: true,
User: {
select: {
name: true,
@@ -185,4 +186,5 @@ export async function POST(request: Request, context: { params: { id: string } }
console.log(error);
return NextResponse.json({ success: false, message: "Gagal mengedit detail tugas, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
}
}
}