upd: tambah upload link

Deskripsi:
- api mobile tambah dan hapus link pada project
- api mobile tambah dan hapus link pada tugas divisi

No Issues
This commit is contained in:
2025-08-14 12:15:33 +08:00
parent 9df5a33386
commit 2c98c2581d
6 changed files with 225 additions and 2 deletions

View File

@@ -0,0 +1,95 @@
import { prisma } from "@/module/_global";
import { funGetUserById } from "@/module/auth";
import { createLogUserMobile } from "@/module/user";
import { NextResponse } from "next/server";
// ADD LINK PROJECT
export async function POST(request: Request, context: { params: { id: string } }) {
try {
const { id } = context.params
const { link, user } = (await request.json())
const userMobile = await funGetUserById({ id: String(user) })
if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") {
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
}
const data = await prisma.project.count({
where: {
id: id
}
})
if (data == 0) {
return NextResponse.json(
{
success: false, message: "Gagal mendapatkan kegiatan, data tidak ditemukan",
},
{ status: 200 }
);
}
const insertLink = await prisma.projectLink.create({
data: {
idProject: id,
link: link
}
})
// create log user
const log = await createLogUserMobile({ act: 'CREATE', desc: 'User menambah link kegiatan', table: 'projectLink', data: insertLink.id, user: userMobile.id })
return NextResponse.json({ success: true, message: "Berhasil menambahkan link kegiatan" }, { status: 200 });
} catch (error) {
console.error(error);
return NextResponse.json({ success: false, message: "Gagal menambah link kegiatan, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
}
}
// DELETE LINK PROJECT
export async function DELETE(request: Request, context: { params: { id: string } }) {
try {
const { idLink, user } = (await request.json())
const userMobile = await funGetUserById({ id: String(user) })
if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") {
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
}
const data = await prisma.projectLink.count({
where: {
id: idLink
}
})
if (data == 0) {
return NextResponse.json(
{
success: false, message: "Gagal mendapatkan link, data tidak ditemukan",
},
{ status: 200 }
);
}
const deleteLink = await prisma.projectLink.update({
where: {
id: idLink
},
data: {
isActive: false
}
})
// create log user
const log = await createLogUserMobile({ act: 'DELETE', desc: 'User menghapus link kegiatan', table: 'projectLink', data: String(idLink), user: userMobile.id })
return NextResponse.json({ success: true, message: "Berhasil menghapus link kegiatan" }, { status: 200 });
} catch (error) {
console.error(error);
return NextResponse.json({ success: false, message: "Gagal menghapus link kegiatan, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
}
}

View File

@@ -136,6 +136,18 @@ export async function GET(request: Request, context: { params: { id: string } })
}))
allData = fix
} else if (kategori == "link") {
const dataLink = await prisma.projectLink.findMany({
where: {
isActive: true,
idProject: String(id)
},
orderBy: {
createdAt: 'asc'
}
})
allData = dataLink
}
return NextResponse.json({ success: true, message: "Berhasil mendapatkan kegiatan", data: allData, }, { status: 200 });

View File

@@ -0,0 +1,98 @@
import { prisma } from "@/module/_global";
import { funGetUserById } from "@/module/auth";
import { createLogUserMobile } from "@/module/user";
import { NextResponse } from "next/server";
// ADD LINK TASK DIVISI
export async function POST(request: Request, context: { params: { id: string } }) {
try {
const { id } = context.params;
const { link, idDivision, user } = (await request.json());
const userMobile = await funGetUserById({ id: String(user) })
if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") {
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
}
const data = await prisma.divisionProject.count({
where: {
id: id,
},
});
if (data == 0) {
return NextResponse.json(
{
success: false,
message: "Tambah link tugas gagal, data tugas tidak ditemukan",
},
{ status: 200 }
);
}
const insertlink = await prisma.divisionProjectLink.create({
data: {
idProject: id,
link,
idDivision,
}
})
// create log user
const log = await createLogUserMobile({ act: 'CREATE', desc: 'User menambahkan link tugas divisi', table: 'divisionProjectLink', data: insertlink.id, user: userMobile.id })
return NextResponse.json({ success: true, message: "Berhasil menambahkan link tugas", }, { status: 200 });
} catch (error) {
console.error(error);
return NextResponse.json({ success: false, message: "Gagal menambah link tugas, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
}
}
// DELETE LINK TASK DIVISI
export async function DELETE(request: Request, context: { params: { id: string } }) {
try {
const { idLink, user } = (await request.json())
const userMobile = await funGetUserById({ id: String(user) })
if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") {
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
}
const data = await prisma.divisionProjectLink.count({
where: {
id: idLink
}
})
if (data == 0) {
return NextResponse.json(
{
success: false, message: "Gagal mendapatkan link, data tidak ditemukan",
},
{ status: 200 }
);
}
const deleteLink = await prisma.divisionProjectLink.update({
where: {
id: idLink
},
data: {
isActive: false
}
})
// create log user
const log = await createLogUserMobile({ act: 'DELETE', desc: 'User menghapus link tugas divisi', table: 'divisionProjectLink', data: String(idLink), user: userMobile.id })
return NextResponse.json({ success: true, message: "Berhasil menghapus link tugas divisi" }, { status: 200 });
} catch (error) {
console.error(error);
return NextResponse.json({ success: false, message: "Gagal menghapus link tugas divisi, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
}
}

View File

@@ -151,6 +151,18 @@ export async function GET(request: Request, context: { params: { id: string } })
}))
allData = fix
} else if (kategori == "link") {
const dataLink = await prisma.divisionProjectLink.findMany({
where: {
isActive: true,
idProject: String(id)
},
orderBy: {
createdAt: 'asc'
}
})
allData = dataLink
}
return NextResponse.json({ success: true, message: "Berhasil mendapatkan tugas divisi", data: allData }, { status: 200 });

View File

@@ -73,9 +73,12 @@ export async function DELETE(request: Request, context: { params: { id: string }
);
}
const deleteLink = await prisma.projectLink.delete({
const deleteLink = await prisma.projectLink.update({
where: {
id: idLink
},
data: {
isActive: false
}
})

View File

@@ -78,9 +78,12 @@ export async function DELETE(request: Request, context: { params: { id: string }
);
}
const deleteLink = await prisma.divisionProjectLink.delete({
const deleteLink = await prisma.divisionProjectLink.update({
where: {
id: idLink
},
data: {
isActive: false
}
})