diff --git a/src/app/(application)/division/page.tsx b/src/app/(application)/division/page.tsx index 2e17ed4..a828285 100644 --- a/src/app/(application)/division/page.tsx +++ b/src/app/(application)/division/page.tsx @@ -1,14 +1,18 @@ import { ViewFilter } from '@/module/_global'; -import { CreateReport, ListDivision } from '@/module/division_new'; -import React from 'react'; +import { CreateReport, NavbarListDivision, TabListDivision } from '@/module/division_new'; +import { Box } from '@mantine/core'; function Page({ searchParams }: { searchParams: { page: string } }) { if (searchParams.page == "filter") - return + return if (searchParams.page == "report") return + return ( - + + + + ); } diff --git a/src/app/api/announcement/route.ts b/src/app/api/announcement/route.ts index 6cc1e2f..f3f8918 100644 --- a/src/app/api/announcement/route.ts +++ b/src/app/api/announcement/route.ts @@ -5,7 +5,6 @@ import moment from "moment"; import "moment/locale/id"; import { NextResponse } from "next/server"; import { createLogUser } from '@/module/user'; - export const dynamic = 'force-dynamic' @@ -99,7 +98,7 @@ export async function GET(request: Request) { return NextResponse.json({ success: true, message: "Berhasil mendapatkan pengumuman", data: allData, }, { status: 200 }); } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mendapatkan pengumuman, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mendapatkan pengumuman, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -207,6 +206,6 @@ export async function POST(request: Request) { } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal membuat pengumuman, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal membuat pengumuman, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } \ No newline at end of file diff --git a/src/app/api/auth/login/route.ts b/src/app/api/auth/login/route.ts index da75009..a4f7447 100644 --- a/src/app/api/auth/login/route.ts +++ b/src/app/api/auth/login/route.ts @@ -23,9 +23,9 @@ export async function POST(req: NextRequest) { phone: user.phone, id: user.id, }); - + } catch (error) { console.error(error); - return Response.json({ message: "Internal Server Error", success: false }); + return Response.json({ message: "Internal Server Error (error: 500)", success: false }); } } diff --git a/src/app/api/banner/[id]/route.ts b/src/app/api/banner/[id]/route.ts index 22ec8d2..31e2136 100644 --- a/src/app/api/banner/[id]/route.ts +++ b/src/app/api/banner/[id]/route.ts @@ -22,7 +22,7 @@ export async function GET(request: Request, context: { params: { id: string } }) return NextResponse.json({ success: true, message: "Berhasil mendapatkan banner", data }, { status: 200 }); } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mendapatkan banner, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mendapatkan banner, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -53,7 +53,7 @@ export async function DELETE(request: Request, context: { params: { id: string } } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal menghapus banner, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal menghapus banner, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -108,6 +108,6 @@ export async function PUT(request: Request, context: { params: { id: string } }) } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mengupdate banner, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mengupdate banner, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } \ No newline at end of file diff --git a/src/app/api/banner/route.ts b/src/app/api/banner/route.ts index a8010ae..df3525d 100644 --- a/src/app/api/banner/route.ts +++ b/src/app/api/banner/route.ts @@ -25,7 +25,7 @@ export async function GET() { return NextResponse.json({ success: true, message: "Berhasil mendapatkan banner", data }, { status: 200 }); } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mendapatkan data banner, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mendapatkan data banner, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -69,6 +69,6 @@ export async function POST(request: Request) { } } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal menambahkan banner, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal menambahkan banner, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } \ No newline at end of file diff --git a/src/app/api/calender/[id]/member/route.ts b/src/app/api/calender/[id]/member/route.ts index 2fe8cc8..0c20926 100644 --- a/src/app/api/calender/[id]/member/route.ts +++ b/src/app/api/calender/[id]/member/route.ts @@ -26,7 +26,7 @@ export async function GET(request: Request, context: { params: { id: string } }) return NextResponse.json( { success: false, - message: "Gagal mendapatkan calender, data tidak ditemukan", + message: "Gagal mendapatkan kalender, data tidak ditemukan", }, { status: 404 } ); @@ -56,15 +56,10 @@ export async function GET(request: Request, context: { params: { id: string } }) const result = { ...dataCalender, timeStart, timeEnd } - return NextResponse.json({ success: true, message: "Berhasil mendapatkan calender", data: result }, { status: 200 }); + return NextResponse.json({ success: true, message: "Berhasil mendapatkan kalender", data: result }, { status: 200 }); } catch (error) { - return NextResponse.json( - { - success: false, - message: "Gagal mendapatkan calender, data tidak ditemukan", - }, - { status: 404 } + return NextResponse.json( { success: false, message: "Gagal mendapatkan kalender, data tidak ditemukan (error: 500)", }, { status: 500 } ); } } @@ -116,7 +111,7 @@ export async function POST(request: Request, context: { params: { id: string } } return NextResponse.json({ success: true, message: "Berhasil menambahkan anggota", }, { status: 200 }); } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal menambah anggota, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal menambah anggota, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } @@ -171,6 +166,6 @@ export async function DELETE(request: Request, context: { params: { id: string } ); } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mengeluarkan anggota, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mengeluarkan anggota, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } \ No newline at end of file diff --git a/src/app/api/calender/[id]/route.ts b/src/app/api/calender/[id]/route.ts index 96c2d97..7c177b6 100644 --- a/src/app/api/calender/[id]/route.ts +++ b/src/app/api/calender/[id]/route.ts @@ -1,7 +1,7 @@ import { prisma } from "@/module/_global"; import { funGetUserByCookies } from "@/module/auth"; import { createLogUser } from "@/module/user"; -import _, { remove } from "lodash"; +import _ from "lodash"; import moment from "moment"; import { NextResponse } from "next/server"; import { Frequency, RRule } from 'rrule'; @@ -100,16 +100,10 @@ export async function GET(request: Request, context: { params: { id: string } }) } - return NextResponse.json({ success: true, message: "Berhasil mendapatkan calender", data: dataFix }, { status: 200 }); + return NextResponse.json({ success: true, message: "Berhasil mendapatkan kalender", data: dataFix }, { status: 200 }); } catch (error) { - return NextResponse.json( - { - success: false, - message: "Gagal mendapatkan calender, data tidak ditemukan", - }, - { status: 404 } - ); + return NextResponse.json({ success: false, message: "Gagal mendapatkan kalender, data tidak ditemukan (error: 500)", }, { status: 500 }); } } @@ -154,12 +148,7 @@ export async function DELETE(request: Request, context: { params: { id: string } return NextResponse.json({ success: true, message: "Berhasil menghapus acara kalender", data }, { status: 200 }); } catch (error) { - return NextResponse.json( - { - success: false, - message: "Gagal menghapus calender, coba lagi nanti", - }, - { status: 500 } + return NextResponse.json({ success: false, message: "Gagal menghapus kalender, coba lagi nanti (error: 500)", }, { status: 500 } ); } } @@ -260,12 +249,7 @@ export async function PUT(request: Request, context: { params: { id: string } }) return NextResponse.json({ success: true, message: "Berhasil mengedit acara" }, { status: 200 }); } catch (error) { - return NextResponse.json( - { - success: false, - message: "Gagal mengedit acara, coba lagi nanti", - }, - { status: 500 } + return NextResponse.json({ success: false, message: "Gagal mengedit acara, coba lagi nanti (error: 500)", }, { status: 500 } ); } } \ No newline at end of file diff --git a/src/app/api/calender/history/route.ts b/src/app/api/calender/history/route.ts index 7a702c2..c82e429 100644 --- a/src/app/api/calender/history/route.ts +++ b/src/app/api/calender/history/route.ts @@ -1,9 +1,9 @@ -import moment from "moment"; -import { NextResponse } from "next/server"; -import "moment/locale/id"; -import { funGetUserByCookies } from "@/module/auth"; import { prisma } from "@/module/_global"; +import { funGetUserByCookies } from "@/module/auth"; import _ from "lodash"; +import moment from "moment"; +import "moment/locale/id"; +import { NextResponse } from "next/server"; // GET HISTORY export async function GET(request: Request) { @@ -104,6 +104,6 @@ export async function GET(request: Request) { } catch (error) { console.error(error) - return NextResponse.json({ success: false, message: "Gagal mendapatkan riwayat acara kalender, coba lagi nanti" }, { status: 404 }); + return NextResponse.json({ success: false, message: "Gagal mendapatkan riwayat acara kalender, coba lagi nanti (error: 500)" }, { status: 404 }); } } \ No newline at end of file diff --git a/src/app/api/calender/indicator/route.ts b/src/app/api/calender/indicator/route.ts index bc85d13..a53cb2a 100644 --- a/src/app/api/calender/indicator/route.ts +++ b/src/app/api/calender/indicator/route.ts @@ -54,7 +54,7 @@ export async function GET(request: Request) { return NextResponse.json({ success: true, message: "Berhasil mendapatkan list acara", data: result }, { status: 200 }); } catch (error) { - return NextResponse.json({ success: false, message: "Gagal mendapatkan list acara" }, { status: 401 }); + return NextResponse.json({ success: false, message: "Gagal mendapatkan list acara (error: 500)" }, { status: 401 }); } } diff --git a/src/app/api/calender/route.ts b/src/app/api/calender/route.ts index 8e08d38..37cbc76 100644 --- a/src/app/api/calender/route.ts +++ b/src/app/api/calender/route.ts @@ -1,10 +1,10 @@ import { prisma } from "@/module/_global"; import { funGetUserByCookies } from "@/module/auth"; +import { createLogUser } from '@/module/user'; import _ from "lodash"; import moment from "moment"; -import { NextResponse } from "next/server"; import "moment/locale/id"; -import { createLogUser } from '@/module/user'; +import { NextResponse } from "next/server"; import { Frequency, RRule } from 'rrule'; //GET ALL CALENDER @@ -85,15 +85,15 @@ export async function GET(request: Request) { })) - return NextResponse.json({ success: true, message: "Berhasil mendapatkan calender", data: allOmit }, { status: 200 }); + return NextResponse.json({ success: true, message: "Berhasil mendapatkan kalender", data: allOmit }, { status: 200 }); } else { - return NextResponse.json({ success: false, message: "Gagal mendapatkan calender, data tidak ditemukan" }, { status: 404 }); + return NextResponse.json({ success: false, message: "Gagal mendapatkan kalender, data tidak ditemukan" }, { status: 404 }); } } catch (error) { console.error(error) - return NextResponse.json({ success: false, message: "Gagal mendapatkan calender, data tidak ditemukan" }, { status: 404 }); + return NextResponse.json({ success: false, message: "Gagal mendapatkan kalender, data tidak ditemukan (error: 500)" }, { status: 404 }); } } @@ -191,6 +191,6 @@ export async function POST(request: Request) { } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal membuat acara kalender, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal membuat acara kalender, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } \ No newline at end of file diff --git a/src/app/api/discussion/[id]/comment/route.ts b/src/app/api/discussion/[id]/comment/route.ts index 338ef78..e0f0e1c 100644 --- a/src/app/api/discussion/[id]/comment/route.ts +++ b/src/app/api/discussion/[id]/comment/route.ts @@ -48,6 +48,6 @@ export async function POST(request: Request, context: { params: { id: string } } } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal menambah komentar, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal menambah komentar, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } \ No newline at end of file diff --git a/src/app/api/discussion/[id]/route.ts b/src/app/api/discussion/[id]/route.ts index a87bcd3..4ccf71e 100644 --- a/src/app/api/discussion/[id]/route.ts +++ b/src/app/api/discussion/[id]/route.ts @@ -91,7 +91,7 @@ export async function GET(request: Request, context: { params: { id: string } }) } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mendapatkan diskusi, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mendapatkan diskusi, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -140,7 +140,7 @@ export async function DELETE(request: Request, context: { params: { id: string } } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mengedit diskusi, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mengedit diskusi, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -178,7 +178,7 @@ export async function PUT(request: Request, context: { params: { id: string } }) return NextResponse.json({ success: true, message: "Berhasil menghapus diskusi" }, { status: 200 }); } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal menghapus diskusi, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal menghapus diskusi, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -218,6 +218,6 @@ export async function POST(request: Request, context: { params: { id: string } } } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mengedit diskusi, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mengedit diskusi, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } diff --git a/src/app/api/discussion/route.ts b/src/app/api/discussion/route.ts index 6cadf5f..ec3355f 100644 --- a/src/app/api/discussion/route.ts +++ b/src/app/api/discussion/route.ts @@ -1,10 +1,10 @@ import { prisma } from "@/module/_global"; import { funGetUserByCookies } from "@/module/auth"; +import { createLogUser } from "@/module/user"; import _ from "lodash"; import moment from "moment"; -import { NextResponse } from "next/server"; import "moment/locale/id"; -import { createLogUser } from "@/module/user"; +import { NextResponse } from "next/server"; // GET ALL DISCUSSION DIVISION ACTIVE = TRUE @@ -86,7 +86,7 @@ export async function GET(request: Request) { } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mendapatkan diskusi, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mendapatkan diskusi, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -180,6 +180,6 @@ export async function POST(request: Request) { return NextResponse.json({ success: true, message: "Berhasil menambahkan diskusi", notif: dataNotif }, { status: 200 }); } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal menambahkan diskusi, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal menambahkan diskusi, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } }; \ No newline at end of file diff --git a/src/app/api/division/[id]/detail/route.ts b/src/app/api/division/[id]/detail/route.ts index da6d7f5..b018447 100644 --- a/src/app/api/division/[id]/detail/route.ts +++ b/src/app/api/division/[id]/detail/route.ts @@ -23,7 +23,7 @@ export async function GET(request: Request, context: { params: { id: string } }) const data = await prisma.division.findUnique({ where: { id: String(id), - isActive: true + // isActive: true } }); @@ -179,7 +179,7 @@ export async function GET(request: Request, context: { params: { id: string } }) catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mendapatkan divisi, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mendapatkan divisi, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -232,7 +232,7 @@ export async function DELETE(request: Request, context: { params: { id: string } ); } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mengeluarkan anggota divisi, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mengeluarkan anggota divisi, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -286,7 +286,7 @@ export async function PUT(request: Request, context: { params: { id: string } }) ); } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mengubah status admin divisi, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mengubah status admin divisi, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -337,6 +337,6 @@ export async function POST(request: Request, context: { params: { id: string } } return NextResponse.json({ success: true, message: "Berhasil menambahkan anggota divisi" }, { status: 200 }); } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal menambahkan anggota divisi, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal menambahkan anggota divisi, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } }; \ No newline at end of file diff --git a/src/app/api/division/[id]/member/route.ts b/src/app/api/division/[id]/member/route.ts index b396f89..5439a41 100644 --- a/src/app/api/division/[id]/member/route.ts +++ b/src/app/api/division/[id]/member/route.ts @@ -65,6 +65,6 @@ export async function GET(request: Request, context: { params: { id: string } }) return NextResponse.json({ success: true, data: fixMember }) } catch (error) { - return NextResponse.json({ success: false, message: "Gagal mendapatkan member, data tidak ditemukan", }, { status: 404 }); + return NextResponse.json({ success: false, message: "Gagal mendapatkan anggota, data tidak ditemukan (error: 500)", }, { status: 500 }); } } \ No newline at end of file diff --git a/src/app/api/division/[id]/route.ts b/src/app/api/division/[id]/route.ts index eb81f1c..efe6316 100644 --- a/src/app/api/division/[id]/route.ts +++ b/src/app/api/division/[id]/route.ts @@ -17,7 +17,7 @@ export async function GET(request: Request, context: { params: { id: string } }) const data = await prisma.division.findUnique({ where: { id: String(id), - isActive: true + // isActive: true } }); @@ -63,7 +63,7 @@ export async function GET(request: Request, context: { params: { id: string } }) } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mendapatkan divisi, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mendapatkan divisi, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -117,6 +117,6 @@ export async function PUT(request: Request, context: { params: { id: string } }) ); } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mengedit divisi, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mengedit divisi, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } \ No newline at end of file diff --git a/src/app/api/division/[id]/status/route.ts b/src/app/api/division/[id]/status/route.ts new file mode 100644 index 0000000..6e17164 --- /dev/null +++ b/src/app/api/division/[id]/status/route.ts @@ -0,0 +1,48 @@ +import { prisma } from "@/module/_global"; +import { funGetUserByCookies } from "@/module/auth"; +import { createLogUser } from "@/module/user"; +import { NextResponse } from "next/server"; + +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 { isActive } = (await request.json()); + const data = await prisma.division.count({ + where: { + id: id, + }, + }); + + if (data == 0) { + return NextResponse.json( + { + success: false, + message: "Edit status divisi gagal, data tidak ditemukan", + }, + { status: 404 } + ); + } + + const update = await prisma.division.update({ + where: { + id: id, + }, + data: { + isActive: !isActive, + }, + }); + + // create log user + const log = await createLogUser({ act: 'UPDATE', desc: 'User mengedit status data divisi', table: 'division', data: id }) + + return NextResponse.json({ success: true, message: "Status divisi berhasil diupdate", }, { status: 200 }); + + } catch (error) { + console.error(error); + return NextResponse.json({ success: false, message: "Gagal mengubah status divisi, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); + } +} \ No newline at end of file diff --git a/src/app/api/division/more/route.ts b/src/app/api/division/more/route.ts index d61e06d..9afb71b 100644 --- a/src/app/api/division/more/route.ts +++ b/src/app/api/division/more/route.ts @@ -1,6 +1,5 @@ import { prisma } from "@/module/_global"; import { funGetUserByCookies } from "@/module/auth"; -import _ from "lodash"; import { NextResponse } from "next/server"; // GET LIST DIVISI BY ID DIVISI (CONTOH : UNTUK SHARE DOKUMEN) @@ -48,6 +47,6 @@ export async function GET(request: Request) { } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mendapatkan divisi, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mendapatkan divisi, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } \ No newline at end of file diff --git a/src/app/api/division/report/route.ts b/src/app/api/division/report/route.ts index 0645bd9..1f7fe32 100644 --- a/src/app/api/division/report/route.ts +++ b/src/app/api/division/report/route.ts @@ -1,12 +1,11 @@ import { prisma } from "@/module/_global"; import { funGetUserByCookies } from "@/module/auth"; -import _, { ceil } from "lodash"; +import _ from "lodash"; import moment from "moment"; import { NextResponse } from "next/server"; export async function GET(request: Request) { try { - const user = await funGetUserByCookies() const { searchParams } = new URL(request.url) const group = searchParams.get("group") @@ -193,6 +192,6 @@ export async function GET(request: Request) { } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mendapatkan data, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mendapatkan data, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } \ No newline at end of file diff --git a/src/app/api/division/route.ts b/src/app/api/division/route.ts index 28528ba..38f2b72 100644 --- a/src/app/api/division/route.ts +++ b/src/app/api/division/route.ts @@ -20,6 +20,7 @@ export async function GET(request: Request) { const idGroup = searchParams.get("group"); const name = searchParams.get('search'); const page = searchParams.get('page'); + const active = searchParams.get("active"); const dataSkip = Number(page) * 10 - 10; if (idGroup == "null" || idGroup == undefined) { @@ -30,7 +31,7 @@ export async function GET(request: Request) { let kondisi: any = { - isActive: true, + isActive: active == 'false' ? false : true, idVillage: String(villaId), idGroup: grup, name: { @@ -41,7 +42,7 @@ export async function GET(request: Request) { if (roleUser != "supadmin" && roleUser != "cosupadmin" && roleUser != "admin") { kondisi = { - isActive: true, + isActive: active == 'false' ? false : true, idVillage: String(villaId), idGroup: grup, name: { @@ -104,7 +105,7 @@ export async function GET(request: Request) { } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mendapatkan divisi, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mendapatkan divisi, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -226,6 +227,6 @@ export async function POST(request: Request) { return NextResponse.json({ success: true, message: "Berhasil menambahkan divisi", notif: dataNotif, }, { status: 200 }); } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal menambahkan divisi, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal menambahkan divisi, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } }; \ No newline at end of file diff --git a/src/app/api/document/more/route.ts b/src/app/api/document/more/route.ts index 20a697c..9e833ab 100644 --- a/src/app/api/document/more/route.ts +++ b/src/app/api/document/more/route.ts @@ -73,7 +73,7 @@ export async function POST(request: Request) { return NextResponse.json({ success: true, message: "Berhasil memindahkan item" }, { status: 200 }); } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal memindahkan item, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal memindahkan item, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } }; @@ -157,7 +157,7 @@ export async function PUT(request: Request) { } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal salin item, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal salin item, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } }; @@ -197,6 +197,6 @@ export async function DELETE(request: Request) { return NextResponse.json({ success: true, message: "Berhasil membagikan item" }, { status: 200 }); } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal membagikan item, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal membagikan item, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } }; \ No newline at end of file diff --git a/src/app/api/document/route.ts b/src/app/api/document/route.ts index 89ebcc3..d8ef815 100644 --- a/src/app/api/document/route.ts +++ b/src/app/api/document/route.ts @@ -110,7 +110,7 @@ export async function GET(request: Request) { select: { DivisionDocumentFolderFile: { select: { - idStorage: true, + idStorage: true, id: true, category: true, name: true, @@ -220,7 +220,7 @@ export async function GET(request: Request) { } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mendapatkan item, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mendapatkan item, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -296,7 +296,7 @@ export async function POST(request: Request) { return NextResponse.json({ success: true, message: "Berhasil membuat folder baru" }, { status: 200 }); } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal membuat folder, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal membuat folder, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } }; @@ -356,7 +356,7 @@ export async function PUT(request: Request) { return NextResponse.json({ success: true, message: "Berhasil mengubah nama item" }, { status: 200 }); } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mengubah nama item, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mengubah nama item (error: 500), coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); } }; @@ -390,6 +390,6 @@ export async function DELETE(request: Request) { return NextResponse.json({ success: true, message: "Berhasil menghapus item" }, { status: 200 }); } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal menghapus item, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal menghapus item, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } }; \ No newline at end of file diff --git a/src/app/api/document/upload/route.ts b/src/app/api/document/upload/route.ts index 6dd776f..470f80a 100644 --- a/src/app/api/document/upload/route.ts +++ b/src/app/api/document/upload/route.ts @@ -1,10 +1,8 @@ import { DIR, funUploadFile, prisma } from "@/module/_global"; import { funGetUserByCookies } from "@/module/auth"; +import { createLogUser } from "@/module/user"; import _ from "lodash"; import { NextResponse } from "next/server"; -import fs from "fs"; -import path from "path"; -import { createLogUser } from "@/module/user"; // UPLOAD FILE @@ -95,6 +93,6 @@ export async function POST(request: Request) { } } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal upload file, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal upload file, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } }; \ No newline at end of file diff --git a/src/app/api/group/[id]/route.ts b/src/app/api/group/[id]/route.ts index 2c9652f..76c453d 100644 --- a/src/app/api/group/[id]/route.ts +++ b/src/app/api/group/[id]/route.ts @@ -5,6 +5,7 @@ import { NextResponse } from "next/server"; export const dynamic = 'force-dynamic' export const revalidate = true + export async function GET(request: Request, context: { params: { id: string } }) { try { const { id } = context.params; @@ -39,7 +40,7 @@ export async function GET(request: Request, context: { params: { id: string } }) ); } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mendapatkan grup, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mendapatkan grup, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -79,11 +80,11 @@ export async function DELETE(request: Request, context: { params: { id: string } // create log user const log = await createLogUser({ act: 'UPDATE', desc: 'User mengedit status data grup', table: 'group', data: id }) - return NextResponse.json( { success: true, message: "Grup berhasil diedit", data, }, { status: 200 } ); + return NextResponse.json({ success: true, message: "Grup berhasil diedit", data, }, { status: 200 }); } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mengedit grup, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mengedit grup, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -124,10 +125,10 @@ export async function PUT(request: Request, context: { params: { id: string } }) // create log user const log = await createLogUser({ act: 'UPDATE', desc: 'User mengedit data grup', table: 'group', data: id }) - return NextResponse.json( { success: true, message: "Grup berhasil diedit", data, }, { status: 200 } ); + return NextResponse.json({ success: true, message: "Grup berhasil diedit", data, }, { status: 200 }); } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mengedit grup, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mengedit grup, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } \ No newline at end of file diff --git a/src/app/api/group/route.ts b/src/app/api/group/route.ts index ae855d5..aa8394f 100644 --- a/src/app/api/group/route.ts +++ b/src/app/api/group/route.ts @@ -6,6 +6,7 @@ import { NextResponse } from "next/server"; export const dynamic = 'force-dynamic' export const revalidate = true + export async function GET(request: Request) { try { const user = await funGetUserByCookies() @@ -41,7 +42,7 @@ export async function GET(request: Request) { } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mendapatkan grup, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mendapatkan grup, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -77,6 +78,6 @@ export async function POST(request: Request) { return NextResponse.json({ success: true, message: "Berhasil menambahkan grup", data, }, { status: 200 }); } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal menambahkan grup, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal menambahkan grup, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } }; \ No newline at end of file diff --git a/src/app/api/home/notification/route.ts b/src/app/api/home/notification/route.ts index 0aebe27..77c3dbb 100644 --- a/src/app/api/home/notification/route.ts +++ b/src/app/api/home/notification/route.ts @@ -8,88 +8,88 @@ import { NextResponse } from "next/server"; // GET ALL NOTIFIKASI export async function GET(request: Request) { - try { - const user = await funGetUserByCookies(); - if (user.id == undefined) { - return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 }); - } + try { + const user = await funGetUserByCookies(); + if (user.id == undefined) { + return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 }); + } - const { searchParams } = new URL(request.url); - const page = searchParams.get('page'); - const dataSkip = Number(page) * 10 - 10; + const { searchParams } = new URL(request.url); + const page = searchParams.get('page'); + const dataSkip = Number(page) * 10 - 10; - const announcements = await prisma.notifications.findMany({ - skip: dataSkip, - take: 10, - where: { - isActive: true, - idUserTo: user.id - }, - orderBy: [ - { - isRead: 'asc' + const announcements = await prisma.notifications.findMany({ + skip: dataSkip, + take: 10, + where: { + isActive: true, + idUserTo: user.id }, - { - createdAt: 'desc' - } - ] + orderBy: [ + { + isRead: 'asc' + }, + { + createdAt: 'desc' + } + ] - }); + }); - const allData = announcements.map((v: any) => ({ - ..._.omit(v, ["createdAt"]), - createdAt: moment(v.createdAt).format("ll") - })) + const allData = announcements.map((v: any) => ({ + ..._.omit(v, ["createdAt"]), + createdAt: moment(v.createdAt).format("ll") + })) - return NextResponse.json({ success: true, message: "Berhasil mendapatkan notifikasi", data: allData, }, { status: 200 }); - } catch (error) { - console.error(error); - return NextResponse.json({ success: false, message: "Gagal mendapatkan notifikasi, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); - } + return NextResponse.json({ success: true, message: "Berhasil mendapatkan notifikasi", data: allData, }, { status: 200 }); + } catch (error) { + console.error(error); + return NextResponse.json({ success: false, message: "Gagal mendapatkan notifikasi, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); + } } // UPDATE READ NOTIFIKASI export async function PUT(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 } = await request.json(); - const data = await prisma.notifications.count({ - where: { - id: id, - }, - }); + 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 } = await request.json(); + const data = await prisma.notifications.count({ + where: { + id: id, + }, + }); - if (data == 0) { - return NextResponse.json( - { - success: false, - message: "Gagal mendapatkan data, data tidak ditemukan", - }, - { status: 404 } - ); - } + if (data == 0) { + return NextResponse.json( + { + success: false, + message: "Gagal mendapatkan data, data tidak ditemukan", + }, + { status: 404 } + ); + } - const result = await prisma.notifications.update({ - where: { - id: id, - }, - data: { - isRead: true, - }, - }); + const result = await prisma.notifications.update({ + where: { + id: id, + }, + data: { + isRead: true, + }, + }); - // create log user - const log = await createLogUser({ act: 'UPDATE', desc: 'User membaca notifikasi', table: 'notifications', data: id }) + // create log user + const log = await createLogUser({ act: 'UPDATE', desc: 'User membaca notifikasi', table: 'notifications', data: id }) - return NextResponse.json( { success: true, message: "Berhasil mendapatkan notifikasi", }, { status: 200 } ); + return NextResponse.json({ success: true, message: "Berhasil mendapatkan notifikasi", }, { status: 200 }); - } catch (error) { - console.error(error); - return NextResponse.json({ success: false, message: "Gagal mendapatkan notifikasi, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); - } + } catch (error) { + console.error(error); + return NextResponse.json({ success: false, message: "Gagal mendapatkan notifikasi, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); + } } \ No newline at end of file diff --git a/src/app/api/home/route.ts b/src/app/api/home/route.ts index 0e1d147..aee2186 100644 --- a/src/app/api/home/route.ts +++ b/src/app/api/home/route.ts @@ -1,6 +1,6 @@ import { prisma } from "@/module/_global"; import { funGetUserByCookies } from "@/module/auth"; -import _, { ceil, some } from "lodash"; +import _, { ceil } from "lodash"; import moment from "moment"; import "moment/locale/id"; import { NextResponse } from "next/server"; @@ -451,6 +451,6 @@ export async function GET(request: Request) { } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mendapatkan data, coba lagi nanti 99", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mendapatkan data, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } \ No newline at end of file diff --git a/src/app/api/home/search/route.ts b/src/app/api/home/search/route.ts index 103220d..709ead4 100644 --- a/src/app/api/home/search/route.ts +++ b/src/app/api/home/search/route.ts @@ -1,12 +1,9 @@ - - -// SEARCH USER, DIVISION, PROJECT - import { prisma } from "@/module/_global"; import { funGetUserByCookies } from "@/module/auth"; import _ from "lodash"; import { NextResponse } from "next/server"; +// SEARCH USER, DIVISION, PROJECT export async function GET(request: Request) { try { const { searchParams } = new URL(request.url) @@ -136,6 +133,6 @@ export async function GET(request: Request) { return NextResponse.json({ success: true, data: allDataSearch }, { status: 200 }); } catch (error) { - return NextResponse.json({ success: false, message: error }, { status: 500 }); + return NextResponse.json({ success: false, message: 'Gagal mendapatkan data, coba lagi nanti (error: 500)' }, { status: 500 }); } } \ No newline at end of file diff --git a/src/app/api/position/[id]/route.ts b/src/app/api/position/[id]/route.ts index f469d63..ec99f28 100644 --- a/src/app/api/position/[id]/route.ts +++ b/src/app/api/position/[id]/route.ts @@ -1,7 +1,6 @@ import { prisma } from "@/module/_global"; import { funGetUserByCookies } from "@/module/auth"; import { createLogUser } from "@/module/user"; -import { revalidatePath } from "next/cache"; import { NextResponse } from "next/server"; // GET ONE JABATAN @@ -42,7 +41,7 @@ export async function GET(request: Request, context: { params: { id: string } }) ); } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mendapatkan jabatan, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mendapatkan jabatan, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -89,7 +88,7 @@ export async function DELETE(request: Request, context: { params: { id: string } ); } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mengubah status jabatan, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mengubah status jabatan, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -135,6 +134,6 @@ export async function PUT(request: Request, context: { params: { id: string } }) } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mengedit jabatan, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mengedit jabatan, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } \ No newline at end of file diff --git a/src/app/api/position/route.ts b/src/app/api/position/route.ts index be5acd7..0b0675d 100644 --- a/src/app/api/position/route.ts +++ b/src/app/api/position/route.ts @@ -9,7 +9,6 @@ import { NextResponse } from "next/server"; // GET ALL POSITION export async function GET(request: Request) { try { - let grup const { searchParams } = new URL(request.url); const idGroup = searchParams.get("group"); @@ -76,7 +75,7 @@ export async function GET(request: Request) { return NextResponse.json({ success: true, message: "Berhasil mendapatkan jabatan", data: allData, filter }, { status: 200 }); } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mendapatkan jabatan, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mendapatkan jabatan, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -135,6 +134,6 @@ export async function POST(request: Request) { } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal menambahkan jabatan, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal menambahkan jabatan, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } diff --git a/src/app/api/project/[id]/member/route.ts b/src/app/api/project/[id]/member/route.ts index a50fa59..a5719c2 100644 --- a/src/app/api/project/[id]/member/route.ts +++ b/src/app/api/project/[id]/member/route.ts @@ -166,10 +166,10 @@ export async function GET(request: Request, context: { params: { id: string } }) member: fixMember } - return NextResponse.json({ success: true, message: "Berhasil mendapatkan project", data: dataFix, }, { status: 200 }); + return NextResponse.json({ success: true, message: "Berhasil mendapatkan kegiatan", data: dataFix, }, { status: 200 }); } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mendapatkan project, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mendapatkan kegiatan, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } \ No newline at end of file diff --git a/src/app/api/project/detail/[id]/route.ts b/src/app/api/project/detail/[id]/route.ts index bdfb0f7..d0c4cf8 100644 --- a/src/app/api/project/detail/[id]/route.ts +++ b/src/app/api/project/detail/[id]/route.ts @@ -82,7 +82,7 @@ export async function DELETE(request: Request, context: { params: { id: string } ); } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal menghapus tahapan kegiatan, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal menghapus tahapan kegiatan, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -159,7 +159,7 @@ export async function PUT(request: Request, context: { params: { id: string } }) } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mengupdate status tahapan kegiatan, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mengupdate status tahapan kegiatan, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -183,16 +183,16 @@ export async function GET(request: Request, context: { params: { id: string } }) if (!data) { return NextResponse.json( { - success: false, message: "Gagal mendapatkan project, data tidak ditemukan", + success: false, message: "Gagal mendapatkan kegiatan, data tidak ditemukan", }, { status: 404 } ); } - return NextResponse.json({ success: true, message: "Detail project berhasil ditemukan", data }, { status: 200 }); + return NextResponse.json({ success: true, message: "Detail kegiatan berhasil ditemukan", data }, { status: 200 }); } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mendapatkan project, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mendapatkan kegiatan, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -243,6 +243,6 @@ export async function POST(request: Request, context: { params: { id: string } } } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mengupdate detail tahapan kegiatan, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mengupdate detail tahapan kegiatan, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } \ No newline at end of file diff --git a/src/app/api/project/file/[id]/route.ts b/src/app/api/project/file/[id]/route.ts index 0d51d27..30f3965 100644 --- a/src/app/api/project/file/[id]/route.ts +++ b/src/app/api/project/file/[id]/route.ts @@ -1,10 +1,8 @@ import { DIR, funDeleteFile, funUploadFile, prisma } from "@/module/_global"; import { funGetUserByCookies } from "@/module/auth"; -import { NextResponse } from "next/server"; -import fs from "fs"; -import path from "path"; -import _ from "lodash"; import { createLogUser } from "@/module/user"; +import _ from "lodash"; +import { NextResponse } from "next/server"; // HAPUS FILE PROJECT BUKAN PAKE ISACTIVE export async function DELETE(request: Request, context: { params: { id: string } }) { @@ -59,7 +57,7 @@ export async function DELETE(request: Request, context: { params: { id: string } } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal menghapus file, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal menghapus file, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -122,7 +120,7 @@ export async function PUT(request: Request, context: { params: { id: string } }) } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Upload file gagal, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Upload file gagal, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -196,6 +194,6 @@ export async function POST(request: Request, context: { params: { id: string } } } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mengupload file, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mengupload file, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } \ No newline at end of file diff --git a/src/app/api/project/route.ts b/src/app/api/project/route.ts index a8d79a7..54d4943 100644 --- a/src/app/api/project/route.ts +++ b/src/app/api/project/route.ts @@ -1,9 +1,9 @@ import { DIR, funUploadFile, prisma } from "@/module/_global"; import { funGetUserByCookies } from "@/module/auth"; +import { createLogUser } from "@/module/user"; import _ from "lodash"; import moment from "moment"; import { NextResponse } from "next/server"; -import { createLogUser } from "@/module/user"; // GET ALL DATA PROJECT @@ -120,7 +120,7 @@ export async function GET(request: Request) { } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mendapatkan kegiatan, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mendapatkan kegiatan, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -277,6 +277,6 @@ export async function POST(request: Request) { } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal membuat kegiatan, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal membuat kegiatan, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } \ No newline at end of file diff --git a/src/app/api/role-user/route.ts b/src/app/api/role-user/route.ts index c38698b..eb809f8 100644 --- a/src/app/api/role-user/route.ts +++ b/src/app/api/role-user/route.ts @@ -21,6 +21,6 @@ export async function GET(request: Request) { return NextResponse.json({ success: true, message: "Berhasil mendapatkan role user", data: res, }, { status: 200 }); } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mendapatkan role user, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mendapatkan role user, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } \ No newline at end of file diff --git a/src/app/api/task/[id]/member/route.ts b/src/app/api/task/[id]/member/route.ts index caf5f77..4507152 100644 --- a/src/app/api/task/[id]/member/route.ts +++ b/src/app/api/task/[id]/member/route.ts @@ -48,10 +48,10 @@ export async function POST(request: Request, context: { params: { id: string } } const log = await createLogUser({ act: 'CREATE', desc: 'User menambahkan anggota tugas divisi', table: 'divisionProject', data: id }) - return NextResponse.json( { success: true, message: "Berhasil menambahkan anggota tugas", }, { status: 200 } ); + return NextResponse.json({ success: true, message: "Berhasil menambahkan anggota tugas", }, { status: 200 }); } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal menambah anggota tugas, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal menambah anggota tugas, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -93,9 +93,9 @@ export async function DELETE(request: Request, context: { params: { id: string } // create log user const log = await createLogUser({ act: 'DELETE', desc: 'User mengeluarkan anggota dari tugas divisi', table: 'divisionProject', data: id }) - return NextResponse.json( { success: true, message: "Berhasil mengeluarkan anggota", }, { status: 200 } ); + return NextResponse.json({ success: true, message: "Berhasil mengeluarkan anggota", }, { status: 200 }); } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mengeluarkan anggota, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mengeluarkan anggota, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } diff --git a/src/app/api/task/[id]/route.ts b/src/app/api/task/[id]/route.ts index 6f3da5d..b402d56 100644 --- a/src/app/api/task/[id]/route.ts +++ b/src/app/api/task/[id]/route.ts @@ -3,7 +3,7 @@ import { funGetUserByCookies } from "@/module/auth"; import { createLogUser } from "@/module/user"; import _ from "lodash"; import moment from "moment"; -import "moment/locale/id" +import "moment/locale/id"; import { NextResponse } from "next/server"; @@ -157,7 +157,7 @@ export async function GET(request: Request, context: { params: { id: string } }) } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mendapatkan tugas divisi, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mendapatkan tugas divisi, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -235,7 +235,7 @@ export async function POST(request: Request, context: { params: { id: string } } return NextResponse.json({ success: true, message: "Detail tugas berhasil ditambahkan", data, }, { status: 200 }); } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mengedit detail tugas, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mengedit detail tugas, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -283,7 +283,7 @@ export async function DELETE(request: Request, context: { params: { id: string } return NextResponse.json({ success: true, message: "Tugas berhasil dibatalkan", }, { status: 200 }); } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal membatalkan tugas, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal membatalkan tugas, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -329,7 +329,7 @@ export async function PUT(request: Request, context: { params: { id: string } }) return NextResponse.json({ success: true, message: "Tugas berhasil diedit", }, { status: 200 }); } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mengedit tugas, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mengedit tugas, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } diff --git a/src/app/api/task/detail/[id]/route.ts b/src/app/api/task/detail/[id]/route.ts index 4989183..2d9f6dc 100644 --- a/src/app/api/task/detail/[id]/route.ts +++ b/src/app/api/task/detail/[id]/route.ts @@ -74,7 +74,7 @@ export async function DELETE(request: Request, context: { params: { id: string } return NextResponse.json({ success: true, message: "Tugas berhasil dihapus", data, }, { status: 200 }); } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal menghapus tugas divisi, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal menghapus tugas divisi, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -149,7 +149,7 @@ export async function PUT(request: Request, context: { params: { id: string } }) return NextResponse.json({ success: true, message: "Status detail tugas berhasil diupdate", data, }, { status: 200 }); } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mengupdate status detail tugas, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mengupdate status detail tugas, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -180,7 +180,7 @@ export async function GET(request: Request, context: { params: { id: string } }) } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mendapatkan detail tugas divisi, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mendapatkan detail tugas divisi, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -229,6 +229,6 @@ export async function POST(request: Request, context: { params: { id: string } } return NextResponse.json({ success: true, message: "Detail tugas berhasil diedit", data, }, { status: 200 }); } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mengedit detail tugas, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mengedit detail tugas, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } \ No newline at end of file diff --git a/src/app/api/task/file/[id]/route.ts b/src/app/api/task/file/[id]/route.ts index 7796b3f..4eab50b 100644 --- a/src/app/api/task/file/[id]/route.ts +++ b/src/app/api/task/file/[id]/route.ts @@ -1,10 +1,9 @@ import { DIR, funDeleteFile, funUploadFile, prisma } from "@/module/_global"; import { funGetUserByCookies } from "@/module/auth"; +import { createLogUser } from "@/module/user"; import _ from "lodash"; import { NextResponse } from "next/server"; -import fs from "fs"; import path from "path"; -import { createLogUser } from "@/module/user"; // HAPUS DETAIL FILE, HAPUS FILE DI ASSETS DAN DATABASE (BUKAN PAKE ISACTIVE) export async function DELETE(request: Request, context: { params: { id: string } }) { @@ -63,7 +62,7 @@ export async function DELETE(request: Request, context: { params: { id: string } } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal menghapus file, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal menghapus file, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -152,7 +151,7 @@ export async function POST(request: Request, context: { params: { id: string } } } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal menambahkan filae, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal menambahkan filae, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -219,6 +218,6 @@ export async function PUT(request: Request, context: { params: { id: string } }) } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Upload file gagal, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Upload file gagal, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } \ No newline at end of file diff --git a/src/app/api/task/route.ts b/src/app/api/task/route.ts index 38e552f..3cfa33a 100644 --- a/src/app/api/task/route.ts +++ b/src/app/api/task/route.ts @@ -94,7 +94,7 @@ export async function GET(request: Request) { } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mendapatkan divisi, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mendapatkan divisi, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -261,10 +261,10 @@ export async function POST(request: Request) { const log = await createLogUser({ act: 'CREATE', desc: 'User membuat tugas divisi baru', table: 'divisionProject', data: data.id }) - return NextResponse.json({ success: true, message: "Berhasil membuat tugas divisi", notif:dataNotif }, { status: 200 }); + return NextResponse.json({ success: true, message: "Berhasil membuat tugas divisi", notif: dataNotif }, { status: 200 }); } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal membuat tugas divisi, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal membuat tugas divisi, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } \ No newline at end of file diff --git a/src/app/api/theme/[id]/route.ts b/src/app/api/theme/[id]/route.ts index 2621f13..9995a73 100644 --- a/src/app/api/theme/[id]/route.ts +++ b/src/app/api/theme/[id]/route.ts @@ -1,7 +1,6 @@ import { prisma } from "@/module/_global"; import { funGetUserByCookies } from "@/module/auth"; import { createLogUser } from "@/module/user"; -import _ from "lodash"; import { NextResponse } from "next/server"; // GET ONE THEME @@ -24,7 +23,7 @@ export async function GET(request: Request, context: { params: { id: string } }) } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mendapatkan member, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mendapatkan tema, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -69,7 +68,7 @@ export async function DELETE(request: Request, context: { params: { id: string } } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal menghapus tema, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal menghapus tema, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -122,7 +121,7 @@ export async function PUT(request: Request, context: { params: { id: string } }) } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mengedit tema, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mengedit tema, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -175,6 +174,6 @@ export async function POST(request: Request, context: { params: { id: string } } } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mengganti tema, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mengganti tema, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } \ No newline at end of file diff --git a/src/app/api/theme/route.ts b/src/app/api/theme/route.ts index e32bea8..666d2d7 100644 --- a/src/app/api/theme/route.ts +++ b/src/app/api/theme/route.ts @@ -45,7 +45,7 @@ export async function GET(request: Request) { return NextResponse.json({ success: true, message: "Berhasil mendapatkan tema", data: result }, { status: 200 }); } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mendapatkan tema, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mendapatkan tema, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -83,6 +83,6 @@ export async function POST(request: Request) { return NextResponse.json({ success: true, message: "Berhasil menambahkan tema" }, { status: 200 }); } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal menambahkan tema, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal menambahkan tema, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } }; \ No newline at end of file diff --git a/src/app/api/user/[id]/route.ts b/src/app/api/user/[id]/route.ts index f1d96c0..24e6875 100644 --- a/src/app/api/user/[id]/route.ts +++ b/src/app/api/user/[id]/route.ts @@ -1,10 +1,8 @@ import { DIR, funDeleteFile, funUploadFile, prisma } from "@/module/_global"; import { funGetUserByCookies } from "@/module/auth"; import { createLogUser } from "@/module/user"; -import _, { update } from "lodash"; +import _ from "lodash"; import { NextResponse } from "next/server"; -import path from "path"; -import fs from "fs"; // GET ONE MEMBER / USER export async function GET(request: Request, context: { params: { id: string } }) { @@ -74,7 +72,7 @@ export async function GET(request: Request, context: { params: { id: string } }) } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mendapatkan member, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mendapatkan anggota, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -131,7 +129,7 @@ export async function DELETE(request: Request, context: { params: { id: string } } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mengupdate status anggota, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mengupdate status anggota, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -234,6 +232,6 @@ export async function PUT(request: Request, context: { params: { id: string } }) } } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mengupdate data anggota, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mengupdate data anggota, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } \ No newline at end of file diff --git a/src/app/api/user/profile/route.ts b/src/app/api/user/profile/route.ts index 2a0ad66..96d8d85 100644 --- a/src/app/api/user/profile/route.ts +++ b/src/app/api/user/profile/route.ts @@ -1,10 +1,8 @@ import { DIR, funDeleteFile, funUploadFile, prisma } from "@/module/_global"; import { funGetUserByCookies } from "@/module/auth"; +import { createLogUser } from "@/module/user"; import _ from "lodash"; import { NextResponse } from "next/server"; -import path from "path"; -import fs from "fs"; -import { createLogUser } from "@/module/user"; // GET PROFILE BY COOKIES @@ -51,7 +49,7 @@ export async function GET(request: Request) { return NextResponse.json({ success: true, data: result }); } catch (error) { - return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 }); + return NextResponse.json({ success: false, message: "Gagal mendapatkan data profile (error: 500)" }, { status: 500 }); } } @@ -140,7 +138,7 @@ export async function PUT(request: Request) { return NextResponse.json({ success: true, message: "Berhasil ubah profile" }); } catch (error) { - return NextResponse.json({ success: false, message: "Gagal ubah profile" }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mengubah profile (error: 500)" }, { status: 500 }); } } diff --git a/src/app/api/user/route.ts b/src/app/api/user/route.ts index 493ef89..ac6250e 100644 --- a/src/app/api/user/route.ts +++ b/src/app/api/user/route.ts @@ -3,8 +3,6 @@ import { funGetUserByCookies } from "@/module/auth"; import { createLogUser } from "@/module/user"; import _ from "lodash"; import { NextResponse } from "next/server"; -import path from "path"; -import fs from "fs"; // GET ALL MEMBER / USER export async function GET(request: Request) { @@ -129,7 +127,7 @@ export async function GET(request: Request) { } catch (error) { console.error(error); - return NextResponse.json({ success: false, message: "Gagal mendapatkan member, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, message: "Gagal mendapatkan anggota, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } @@ -137,7 +135,6 @@ export async function GET(request: Request) { // CREATE MEMBER / USER export async function POST(request: Request) { try { - const user = await funGetUserByCookies() if (user.id == undefined) { return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 }); @@ -212,13 +209,13 @@ export async function POST(request: Request) { // create log user const log = await createLogUser({ act: 'CREATE', desc: 'User membuat data user baru', table: 'user', data: users.id }) - return Response.json({ success: true, message: 'Sukses membuat user', data: users}, { status: 200 }); + return Response.json({ success: true, message: 'Sukses membuat user', data: users }, { status: 200 }); } else { return Response.json({ success: false, message: "User sudah ada" }, { status: 400 }); } } catch (error) { console.error(error); - return Response.json({ success: false, message: "Internal Server Error" }, { status: 500 }); + return Response.json({ success: false, message: "Gagal membuat anggota, coba lagi nanti (error: 500)" }, { status: 500 }); } } \ No newline at end of file diff --git a/src/app/api/version-app/route.ts b/src/app/api/version-app/route.ts index e9404ea..cc30c52 100644 --- a/src/app/api/version-app/route.ts +++ b/src/app/api/version-app/route.ts @@ -5,6 +5,6 @@ export async function GET(request: Request) { return NextResponse.json({ success: true, version: "0.1.5", mode: "staging" }, { status: 200 }); } catch (error) { console.error(error); - return NextResponse.json({ success: false, version: "Gagal mendapatkan version, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + return NextResponse.json({ success: false, version: "Gagal mendapatkan version, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); } } diff --git a/src/module/_global/layout/layout_drawer.tsx b/src/module/_global/layout/layout_drawer.tsx index 804a922..02fb060 100644 --- a/src/module/_global/layout/layout_drawer.tsx +++ b/src/module/_global/layout/layout_drawer.tsx @@ -8,7 +8,7 @@ export default function LayoutDrawer({ opened, onClose, title, children, size }: const tema = useHookstate(TEMA) return ( - {title}} onClose={onClose} position={"bottom"} size={(size == 'lg') ? '80%' : '40%' } + {title}} onClose={onClose} position={"bottom"} size={(size == 'lg') ? '80%' : (size == 'md') ? '45%' : '40%'} styles={{ content: { backgroundColor: "white", diff --git a/src/module/division_new/index.ts b/src/module/division_new/index.ts index d9724fc..90951ea 100644 --- a/src/module/division_new/index.ts +++ b/src/module/division_new/index.ts @@ -17,6 +17,8 @@ import ReportDivisionId from './ui/report_division_id'; import { funGetDivisionById, funGetListDivisionByIdDivision, funGetSearchMemberDivision } from './lib/api_division'; import { globalIsAdminDivision } from './lib/val_division'; import WrapLayoutDivision from './ui/wrap_division'; +import TabListDivision from './ui/tab_list_division'; +import NavbarListDivision from './ui/navbar_list_division'; export { CreateUsers }; export { CreateAdminDivision }; @@ -38,4 +40,6 @@ export { funGetDivisionById } export { funGetListDivisionByIdDivision } export { funGetSearchMemberDivision } export { globalIsAdminDivision } -export { WrapLayoutDivision } \ No newline at end of file +export { WrapLayoutDivision } +export { TabListDivision } +export { NavbarListDivision } \ No newline at end of file diff --git a/src/module/division_new/lib/api_division.ts b/src/module/division_new/lib/api_division.ts index 94c6fe5..7bbcb64 100644 --- a/src/module/division_new/lib/api_division.ts +++ b/src/module/division_new/lib/api_division.ts @@ -87,4 +87,15 @@ export const funGetReportDivision = async (path?: string) => { export const funGetSearchMemberDivision = async (path: string, id: string) => { const response = await fetch(`/api/division/${id}/member/${(path) ? path : ''}`, { next: { tags: ['division'] } }); return await response.json().catch(() => null); -} \ No newline at end of file +} + +export const funUpdateStatusDivision = async (path: string, data: { isActive: boolean }) => { + const response = await fetch(`/api/division/${path}/status`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(data), + }); + return await response.json().catch(() => null); +} diff --git a/src/module/division_new/ui/create_division.tsx b/src/module/division_new/ui/create_division.tsx index c5819d0..22c9373 100644 --- a/src/module/division_new/ui/create_division.tsx +++ b/src/module/division_new/ui/create_division.tsx @@ -3,7 +3,7 @@ import { LayoutNavbarNew, TEMA } from "@/module/_global"; import { funGetUserByCookies } from "@/module/auth"; import { funGetAllGroup, IDataGroup } from "@/module/group"; import { useHookstate } from "@hookstate/core"; -import { Avatar, Box, Button, Divider, Grid, Group, rem, Select, Stack, Text, Textarea, TextInput } from "@mantine/core"; +import { ActionIcon, Avatar, Box, Button, Divider, Grid, Group, rem, Select, Stack, Text, Textarea, TextInput } from "@mantine/core"; import { useMediaQuery, useShallowEffect } from "@mantine/hooks"; import { useRouter } from "next/navigation"; import { useState } from "react"; @@ -12,6 +12,7 @@ import { IoIosArrowDropright } from "react-icons/io"; import { globalMemberDivision } from "../lib/val_division"; import NavbarAdminDivision from "./navbar_admin_division"; import NavbarCreateUsers from "./navbar_create_users"; +import { HiChevronLeft } from "react-icons/hi2"; export default function CreateDivision() { const router = useRouter(); @@ -105,6 +106,10 @@ export default function CreateDivision() { return nilai } + function onBack() { + member.set([]) + router.push('/division') + } if (isChooseAdmin) return { @@ -125,7 +130,15 @@ export default function CreateDivision() { return ( - + + { onBack() }} bg={tema.get().bgIcon} size="lg" radius="lg" aria-label="Settings"> + + + + } + title="Tambah Divisi" menu /> { diff --git a/src/module/division_new/ui/information_division.tsx b/src/module/division_new/ui/information_division.tsx index f5d17fa..929e530 100644 --- a/src/module/division_new/ui/information_division.tsx +++ b/src/module/division_new/ui/information_division.tsx @@ -1,24 +1,26 @@ "use client" -import { globalRole, LayoutDrawer, LayoutNavbarNew, SkeletonList, SkeletonSingle, TEMA } from '@/module/_global'; -import { ActionIcon, Avatar, Box, Button, Divider, Flex, Grid, Group, Skeleton, Stack, Text } from '@mantine/core'; +import { globalRole, LayoutDrawer, LayoutNavbarNew, SkeletonList, TEMA } from '@/module/_global'; +import LayoutModal from '@/module/_global/layout/layout_modal'; +import { funGetUserByCookies } from '@/module/auth'; +import { useHookstate } from '@hookstate/core'; +import { ActionIcon, Avatar, Box, Divider, Flex, Grid, Group, SimpleGrid, Skeleton, Stack, Text } from '@mantine/core'; import { useMediaQuery, useShallowEffect } from '@mantine/hooks'; import { useParams, useRouter } from 'next/navigation'; -import React, { useState } from 'react'; +import { useState } from 'react'; import toast from 'react-hot-toast'; import { AiOutlineUserAdd } from 'react-icons/ai'; -import { FaUserTie } from 'react-icons/fa6'; -import { IoIosCloseCircle } from 'react-icons/io'; -import { LuClipboardEdit } from 'react-icons/lu'; -import { funDeleteMemberDivision, funEditStatusAdminDivision, funGetDivisionById } from '../lib/api_division'; +import { FaPencil, FaToggleOff, FaUserTie } from 'react-icons/fa6'; +import { HiMenu } from 'react-icons/hi'; +import { IoIosCloseCircle, IoIosWarning } from 'react-icons/io'; +import { funDeleteMemberDivision, funEditStatusAdminDivision, funGetDivisionById, funUpdateStatusDivision } from '../lib/api_division'; import { IDataMemberDivision } from '../lib/type_division'; -import LayoutModal from '@/module/_global/layout/layout_modal'; -import { useHookstate } from '@hookstate/core'; -import { funGetUserByCookies } from '@/module/auth'; export default function InformationDivision() { const router = useRouter() const [openDrawer, setDrawer] = useState(false) + const [openDrawerInfo, setDrawerInfo] = useState(false) + const [valActive, setValActive] = useState(true) const param = useParams<{ id: string }>() const [name, setName] = useState('') const [deskripsi, setDeskripsi] = useState('') @@ -28,11 +30,13 @@ export default function InformationDivision() { const [valChooseMemberStatus, setChooseMemberStatus] = useState(false) const [valChooseMemberName, setChooseMemberName] = useState("") const [isOpenModal, setOpenModal] = useState(false) + const [isOpenModalStatus, setOpenModalStatus] = useState(false) const roleLogin = useHookstate(globalRole) const [isAdmin, setAdmin] = useState(false) const isMobile = useMediaQuery('(max-width: 455px)'); const isMobile2 = useMediaQuery("(max-width: 438px)"); const tema = useHookstate(TEMA) + const [loadingStatus, setLoadingStatus] = useState(false) async function getOneData() { try { @@ -43,6 +47,7 @@ export default function InformationDivision() { setName(res.data.division.name); setDeskripsi(res.data.division.desc); setMember(res.data.member) + setValActive(res.data.division.isActive) const cek = res.data.member.some((i: any) => i.idUser == login.id && i.isAdmin == true) setAdmin(cek) } else { @@ -105,20 +110,53 @@ export default function InformationDivision() { } } + async function editStatusDivisi() { + try { + setLoadingStatus(true) + const res = await funUpdateStatusDivision(param.id, { isActive: valActive }) + if (res.success) { + toast.success(res.message) + getOneData() + } else { + toast.error(res.message) + } + } catch (error) { + console.error(error); + toast.error("Gagal mendapatkan divisi, coba lagi nanti"); + } finally { + setDrawerInfo(false) + setLoadingStatus(false) + setOpenModalStatus(false) + } + } + return ( { - router.push('/division/edit/' + param.id) - }} bg={tema.get().bgIcon} size="lg" radius="lg" aria-label="Settings"> - + { setDrawerInfo(true) }} bg={tema.get().bgIcon} size="lg" radius="lg" aria-label="Settings"> + : <> } /> + { + !valActive ? + + + + + Divisi dinonaktifkan + + + + : <> + } + Deskripsi Divisi : - ((roleLogin.get() != 'user' && roleLogin.get() != 'coadmin') || isAdmin) ? + (((roleLogin.get() != 'user' && roleLogin.get() != 'coadmin') || isAdmin) && valActive) ? router.push('/division/add-member/' + param.id)}> @@ -223,17 +261,17 @@ export default function InformationDivision() { setDrawer(false)} title={valChooseMemberName}> - editStatusAdmin()}> + valActive ? editStatusAdmin() : undefined}> - + - {(valChooseMemberStatus == false) ? "Jadikan admin" : "Memberhentikan sebagai admin"} + {(valChooseMemberStatus == false) ? "Jadikan admin" : "Memberhentikan sebagai admin"} - setOpenModal(true)}> + valActive ? setOpenModal(true) : undefined}> - + - Keluarkan dari divisi + Keluarkan dari divisi @@ -247,6 +285,41 @@ export default function InformationDivision() { deleteMember() } }} /> + + setDrawerInfo(false)} title={"Menu"}> + + + + router.push('/division/edit/' + param.id)} justify={'center'} align={'center'} direction={'column'} > + + + + + Edit Divisi + + + { setOpenModalStatus(true) }} justify={'center'} align={'center'} direction={'column'} > + + + + + {valActive ? "Non Aktifkan Divisi" : "Aktifkan Divisi"} + + + + + + + + setOpenModalStatus(false)} + description="Apakah Anda yakin ingin mangubah status aktifasi divisi?" + onYes={(val) => { + if (!val) { + setOpenModalStatus(false) + } else { + editStatusDivisi() + } + }} /> ); } diff --git a/src/module/division_new/ui/list_division.tsx b/src/module/division_new/ui/list_division.tsx index da33735..f38041e 100644 --- a/src/module/division_new/ui/list_division.tsx +++ b/src/module/division_new/ui/list_division.tsx @@ -17,7 +17,6 @@ import DrawerDivision from './drawer_division'; export default function ListDivision() { const [isList, setIsList] = useState(false) const router = useRouter() - const [openDrawer, setOpenDrawer] = useState(false) const [data, setData] = useState([]) const [jumlah, setJumlah] = useState(0) const [searchQuery, setSearchQuery] = useState('') @@ -32,6 +31,7 @@ export default function ListDivision() { const paddingLift = useMediaQuery('(max-width: 505px)') const [isRefresh, setRefresh] = useState(false) const notifLoadPage = useHookstate(globalNotifPage) + const status = searchParams.get('active') const handleList = () => { @@ -40,12 +40,12 @@ export default function ListDivision() { const fetchData = async (loading: boolean) => { try { - + setLoading(loading); if (isPage == 1) { setData([]) } - const response = await funGetAllDivision('?search=' + searchQuery + '&group=' + group + '&page=' + isPage) + const response = await funGetAllDivision('?active=' + status + '&search=' + searchQuery + '&group=' + group + '&page=' + isPage) if (response.success) { setJumlah(response.total) setNameGroup(response.filter.name) @@ -65,14 +65,10 @@ export default function ListDivision() { } }; - function searchDivision(search: string) { - setSearchQuery(search) - setPage(1) - } - useShallowEffect(() => { + setPage(1) fetchData(true) - }, [searchQuery]) + }, [status, searchQuery]) useShallowEffect(() => { @@ -121,15 +117,7 @@ export default function ListDivision() { return ( - (setOpenDrawer(true))} bg={tema.get().bgIcon} size="lg" radius="lg" aria-label="Settings"> - - - } /> - - + { isRefresh && } placeholder="Pencarian" value={searchQuery} - onChange={(val) => { searchDivision(val.target.value) }} + onChange={(val) => { setSearchQuery(val.target.value) }} /> @@ -289,9 +277,6 @@ export default function ListDivision() { )} - setOpenDrawer(false)}> - - ); } \ No newline at end of file diff --git a/src/module/division_new/ui/navbar_list_division.tsx b/src/module/division_new/ui/navbar_list_division.tsx new file mode 100644 index 0000000..d09a152 --- /dev/null +++ b/src/module/division_new/ui/navbar_list_division.tsx @@ -0,0 +1,30 @@ +'use client' +import { globalRole, LayoutDrawer, LayoutNavbarNew, TEMA } from "@/module/_global"; +import { useHookstate } from "@hookstate/core"; +import { ActionIcon } from "@mantine/core"; +import { useState } from "react"; +import { HiMenu } from "react-icons/hi"; +import DrawerDivision from "./drawer_division"; + +export default function NavbarListDivision() { + const roleLogin = useHookstate(globalRole) + const tema = useHookstate(TEMA) + const [openDrawer, setOpenDrawer] = useState(false) + + return ( + <> + (setOpenDrawer(true))} bg={tema.get().bgIcon} size="lg" radius="lg" aria-label="Settings"> + + + : <> + } /> + setOpenDrawer(false)}> + + + + ) +} \ No newline at end of file diff --git a/src/module/division_new/ui/tab_list_division.tsx b/src/module/division_new/ui/tab_list_division.tsx new file mode 100644 index 0000000..0f7ce8d --- /dev/null +++ b/src/module/division_new/ui/tab_list_division.tsx @@ -0,0 +1,65 @@ +"use client"; +import { globalRole, TEMA } from "@/module/_global"; +import { useHookstate } from "@hookstate/core"; +import { Box, rem, Tabs } from "@mantine/core"; +import { useRouter, useSearchParams } from "next/navigation"; +import { IoMdCheckmarkCircleOutline } from "react-icons/io"; +import { IoCloseCircleOutline } from "react-icons/io5"; +import ListDivision from "./list_division"; + +export default function TabListDivision() { + const iconStyle = { width: rem(20), height: rem(20) }; + const router = useRouter(); + const searchParams = useSearchParams(); + const status = searchParams.get("active"); + const group = searchParams.get("group"); + const tema = useHookstate(TEMA) + const roleLogin = useHookstate(globalRole) + + return ( + + + { + roleLogin.get() != '' ? + (roleLogin.get() != "user" && roleLogin.get() != "coadmin") && + + } + onClick={() => { + router.push("/division?active=true&group=" + group); + }} + > + Aktif + + } + onClick={() => { + router.push("/division?active=false&group=" + group); + }} + > + Tidak Aktif + + + : <> + } + + + + ); +} diff --git a/src/module/group/ui/drawer_group.tsx b/src/module/group/ui/drawer_group.tsx index abba7e1..99d70c3 100644 --- a/src/module/group/ui/drawer_group.tsx +++ b/src/module/group/ui/drawer_group.tsx @@ -1,14 +1,6 @@ import { LayoutDrawer, TEMA } from "@/module/_global"; import { useHookstate } from "@hookstate/core"; -import { - Box, - Button, - Flex, - SimpleGrid, - Stack, - Text, - TextInput -} from "@mantine/core"; +import { Box, Button, Flex, SimpleGrid, Stack, Text, TextInput } from "@mantine/core"; import { useState } from "react"; import toast from "react-hot-toast"; import { IoAddCircle } from "react-icons/io5"; @@ -102,7 +94,7 @@ export default function DrawerGroup({ onSuccess, }: { onSuccess: (val: boolean) borderColor: tema.get().utama, }, }} - size="lg" + size="md" radius={10} label="Grup" required diff --git a/src/module/position/ui/drawer_list_position.tsx b/src/module/position/ui/drawer_list_position.tsx index 82a60ae..390d685 100644 --- a/src/module/position/ui/drawer_list_position.tsx +++ b/src/module/position/ui/drawer_list_position.tsx @@ -1,16 +1,16 @@ -import { WARNA, LayoutDrawer, globalRole, TEMA, keyWibu } from "@/module/_global"; +import { globalRole, keyWibu, LayoutDrawer, TEMA } from "@/module/_global"; import { funGetAllGroup, IDataGroup } from "@/module/group"; -import { Box, Stack, SimpleGrid, Flex, TextInput, Button, Text, Select } from "@mantine/core"; +import { useHookstate } from "@hookstate/core"; +import { Box, Button, Flex, Select, SimpleGrid, Stack, Text, TextInput } from "@mantine/core"; import { useShallowEffect } from "@mantine/hooks"; import { useRouter, useSearchParams } from "next/navigation"; -import { useEffect, useState } from "react"; +import { useState } from "react"; import toast from "react-hot-toast"; import { IoAddCircle } from "react-icons/io5"; import { RiFilter2Line } from "react-icons/ri"; -import { funCreatePosition } from "../lib/api_position"; -import { useHookstate } from "@hookstate/core"; -import { globalRefreshPosition } from "../lib/val_posisition"; import { useWibuRealtime } from "wibu-realtime"; +import { funCreatePosition } from "../lib/api_position"; +import { globalRefreshPosition } from "../lib/val_posisition"; export default function DrawerListPosition({ onCreated }: { onCreated: (val: boolean) => void }) { @@ -99,7 +99,7 @@ export default function DrawerListPosition({ onCreated }: { onCreated: (val: boo nilai = false } - if (roleLogin.get() == "supadmin" && listData.idGroup == "") { + if (roleLogin.get() == "supadmin" && (listData.idGroup == "" || String(listData.idGroup) == "null")) { setTouched(touched => ({ ...touched, idGroup: true })) nilai = false } @@ -117,7 +117,7 @@ export default function DrawerListPosition({ onCreated }: { onCreated: (val: boo } } else if (kategori == 'idGroup') { setListData({ ...listData, idGroup: val }) - if (val == "") { + if (val == "" || String(val) == "null") { setTouched({ ...touched, idGroup: true }) } else { setTouched({ ...touched, idGroup: false }) @@ -152,8 +152,8 @@ export default function DrawerListPosition({ onCreated }: { onCreated: (val: boo } - setOpenDrawerGroup(false)} title={'Tambah Jabatan'}> - + setOpenDrawerGroup(false)} title={'Tambah Jabatan'} size="md"> + { roleLogin.get() == "supadmin" &&