upd: refactor folder

This commit is contained in:
amel
2024-08-14 17:42:01 +08:00
parent de7ace8d49
commit a91fd8949c
30 changed files with 100 additions and 670 deletions

View File

@@ -16,6 +16,22 @@ export async function GET(request: Request, context: { params: { id: string } })
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
}
const data = await prisma.announcement.count({
where: {
id: id,
},
});
if (data == 0) {
return NextResponse.json(
{
success: false,
message: "Gagal mendapatkan pengumuman, data tidak ditemukan",
},
{ status: 404 }
);
}
const announcement = await prisma.announcement.findUnique({
where: {
id: id,
@@ -60,7 +76,7 @@ export async function GET(request: Request, context: { params: { id: string } })
return NextResponse.json(
{
success: true,
message: "Berhasil mendapatkan announcement",
message: "Berhasil mendapatkan pengumuman",
data: announcement,
member: fixMember
},
@@ -71,7 +87,7 @@ export async function GET(request: Request, context: { params: { id: string } })
} catch (error) {
console.error(error);
return NextResponse.json({ success: false, message: "Gagal mendapatkan announcement, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
return NextResponse.json({ success: false, message: "Gagal mendapatkan pengumuman, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
}
}
@@ -148,7 +164,7 @@ export async function PUT(request: Request, context: { params: { id: string } })
return NextResponse.json(
{
success: false,
message: "Hapus pengumuman gagal, data tidak ditemukan",
message: "Edit pengumuman gagal, data tidak ditemukan",
},
{ status: 404 }
);

View File

@@ -1,39 +0,0 @@
import { prisma } from "@/module/_global";
import { funGetUserByCookies } from "@/module/auth";
import { revalidatePath, revalidateTag } from "next/cache";
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()
if (user.id == undefined) {
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
}
const villaId = user.idVillage
const data = await prisma.group.findMany({
where: {
isActive: true,
idVillage: String(villaId)
},
select: {
id: true,
name: true,
Division: {
select: {
id: true,
name: true
}
}
}
});
return NextResponse.json({ success: true, message: "Berhasil mendapatkan grup", data, }, { status: 200 });
} catch (error) {
console.log(error);
return NextResponse.json({ success: false, message: "Gagal mendapatkan grup, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
}
}

View File

@@ -13,6 +13,22 @@ export async function POST(request: Request, context: { params: { id: string } }
const { id } = context.params
const { comment } = (await request.json());
const cek = await prisma.divisionDisscussion.count({
where: {
id: id
}
})
if (cek == 0) {
return NextResponse.json(
{
success: false,
message: "Tambah komentar gagal, data tidak ditemukan",
},
{ status: 404 }
);
}
const data = await prisma.divisionDisscussionComment.create({
data: {
comment: comment,
@@ -21,10 +37,10 @@ export async function POST(request: Request, context: { params: { id: string } }
}
})
return NextResponse.json({ success: true, message: "Berhasil mendapatkan diskusi", data: data, }, { status: 200 });
return NextResponse.json({ success: true, message: "Berhasil menambah komentar", data: data, }, { status: 200 });
} catch (error) {
console.log(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 menambah komentar, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
}
}

View File

@@ -15,6 +15,22 @@ export async function GET(request: Request, context: { params: { id: string } })
}
const { id } = context.params
const cek = await prisma.divisionDisscussion.count({
where: {
id: id
}
})
if (cek == 0) {
return NextResponse.json(
{
success: false,
message: "Gagal mendapatkan diskusi, data tidak ditemukan",
},
{ status: 404 }
);
}
const data = await prisma.divisionDisscussion.findUnique({
where: {
id: id
@@ -66,11 +82,11 @@ export async function GET(request: Request, context: { params: { id: string } })
totalComments: comments.length,
};
return NextResponse.json({ success: true, message: "Berhasil mendapatkan divisi", data: response }, { status: 200 });
return NextResponse.json({ success: true, message: "Berhasil mendapatkan diskusi", data: response }, { status: 200 });
} catch (error) {
console.log(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 diskusi, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
}
}
@@ -100,7 +116,7 @@ export async function DELETE(request: Request, context: { params: { id: string }
});
if (data == 0) {
return NextResponse.json({ success: false, message: "Gagal mendapatkan discussion, data tidak ditemukan" }, { status: 404 });
return NextResponse.json({ success: false, message: "Gagal mendapatkan diskusi, data tidak ditemukan" }, { status: 404 });
}
const result = await prisma.divisionDisscussion.update({
@@ -111,11 +127,11 @@ export async function DELETE(request: Request, context: { params: { id: string }
status: newStatus
}
});
return NextResponse.json({ success: true, message: "Berhasil Update discussion" }, { status: 200 });
return NextResponse.json({ success: true, message: "Berhasil mengedit diskusi" }, { status: 200 });
} catch (error) {
console.log(error);
return NextResponse.json({ success: false, message: "Gagal mendapatkan discussion, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
return NextResponse.json({ success: false, message: "Gagal mengedit diskusi, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
}
}
@@ -127,6 +143,18 @@ export async function PUT(request: Request, context: { params: { id: string } })
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
}
const { id } = context.params
const cek = await prisma.divisionDisscussion.count({
where: {
id: id
},
});
if (cek == 0) {
return NextResponse.json({ success: false, message: "Gagal menghapus diskusi, data tidak ditemukan" }, { status: 404 });
}
const data = await prisma.divisionDisscussion.update({
where: {
id: id
@@ -135,10 +163,10 @@ export async function PUT(request: Request, context: { params: { id: string } })
isActive: false
}
});
return NextResponse.json({ success: true, message: "Berhasil Delete discussion" }, { status: 200 });
return NextResponse.json({ success: true, message: "Berhasil menghapus diskusi" }, { status: 200 });
} catch (error) {
console.log(error);
return NextResponse.json({ success: false, message: "Gagal mendapatkan discussion, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
return NextResponse.json({ success: false, message: "Gagal menghapus diskusi, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
}
}
@@ -160,7 +188,7 @@ export async function POST(request: Request, context: { params: { id: string } }
});
if (data == 0) {
return NextResponse.json({ success: false, message: "Gagal mendapatkan discussion, data tidak ditemukan" }, { status: 404 });
return NextResponse.json({ success: false, message: "Gagal mengedit diskusi, data tidak ditemukan" }, { status: 404 });
}
const update = await prisma.divisionDisscussion.update({
@@ -171,10 +199,10 @@ export async function POST(request: Request, context: { params: { id: string } }
desc: desc
}
});
return NextResponse.json({ success: true, message: "Berhasil Edit discussion" }, { status: 200 });
return NextResponse.json({ success: true, message: "Berhasil mengedit diskusi" }, { status: 200 });
} catch (error) {
console.log(error);
return NextResponse.json({ success: false, message: "Gagal mendapatkan discussion, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
return NextResponse.json({ success: false, message: "Gagal mengedit diskusi, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
}
}

View File

@@ -202,7 +202,7 @@ export async function DELETE(request: Request, context: { params: { id: string }
);
} catch (error) {
console.log(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 mengeluarkan anggota divisi, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
}
}
@@ -253,7 +253,7 @@ export async function PUT(request: Request, context: { params: { id: string } })
);
} catch (error) {
console.log(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 mengubah status admin divisi, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
}
}

View File

@@ -111,6 +111,6 @@ export async function PUT(request: Request, context: { params: { id: string } })
);
} catch (error) {
console.log(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 mengedit divisi, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
}
}

View File

@@ -85,7 +85,7 @@ export async function DELETE(request: Request, context: { params: { id: string }
);
} catch (error) {
console.log(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 mengedit grup, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
}
}
@@ -133,6 +133,6 @@ export async function PUT(request: Request, context: { params: { id: string } })
);
} catch (error) {
console.log(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 mengedit grup, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
}
}

View File

@@ -64,7 +64,7 @@ export async function DELETE(request: Request, context: { params: { id: string }
return NextResponse.json(
{
success: false,
message: "Gagal delete jabatan, data tidak ditemukan",
message: "Gagal mengubah status jabatan, data tidak ditemukan",
},
{ status: 404 }
);
@@ -81,12 +81,12 @@ export async function DELETE(request: Request, context: { params: { id: string }
});
return NextResponse.json(
{ success: true, message: "Sukses Delete Position" },
{ success: true, message: "Berhasil mengubah status jabatan" },
{ status: 200 }
);
} catch (error) {
console.error(error);
return NextResponse.json({ success: false, message: "Gagal mendapatkan position, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
return NextResponse.json({ success: false, message: "Gagal mengubah status jabatan, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
}
}
@@ -116,16 +116,16 @@ export async function PUT(request: Request, context: { params: { id: string } })
idGroup: data.idGroup,
},
});
return NextResponse.json({ success: true, message: "Berhasil edit position", positions, }, { status: 200 });
return NextResponse.json({ success: true, message: "Berhasil mengedit jabatan", positions, }, { status: 200 });
} else {
return NextResponse.json(
{ success: false, message: "Position sudah ada" },
{ success: false, message: "Jabatan sudah ada" },
{ status: 400 }
);
}
} 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 mengedit jabatan, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
}
}

View File

@@ -1,6 +0,0 @@
import { apiPosition } from "@/module/position";
import { NextRequest } from "next/server";
export async function GET(req: NextRequest) {
return apiPosition(req, "GET");
}

View File

@@ -1,6 +0,0 @@
import { apiPosition } from "@/module/position";
import { NextRequest } from "next/server";
export async function POST(req: NextRequest) {
return apiPosition(req, "POST");
}

View File

@@ -25,6 +25,17 @@ export async function GET(request: Request) {
grupFix = groupID
}
const cek = await prisma.group.count({
where: {
id: String(grupFix),
isActive: true
}
})
if (cek == 0) {
return NextResponse.json({ success: false, message: "Gagal mendapatkan jabatan, data tidak ditemukan", }, { status: 404 });
}
const positions = await prisma.position.findMany({
where: {
idGroup: String(grupFix),
@@ -91,16 +102,16 @@ export async function POST(request: Request) {
revalidatePath('/position?active=true', 'page')
revalidateTag('position')
return NextResponse.json({ success: true, message: "Berhasil menambahkan position", positions, }, { status: 200 });
return NextResponse.json({ success: true, message: "Berhasil menambahkan jabatan", positions, }, { status: 200 });
} else {
return NextResponse.json(
{ success: false, message: "Position sudah ada" },
{ success: false, message: "Jabatan sudah ada" },
{ status: 400 }
);
}
} catch (error) {
console.error(error);
return NextResponse.json({ success: false, message: "Gagal menambahkan position, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
return NextResponse.json({ success: false, message: "Gagal menambahkan jabatan, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
}
}

View File

@@ -1,7 +0,0 @@
import { apiUser } from "@/module/user";
import { NextRequest } from "next/server";
export async function GET(req: NextRequest) {
return apiUser(req, "GET")
}

View File

@@ -1,7 +0,0 @@
import { apiUser } from "@/module/user";
import { NextRequest } from "next/server";
export async function POST(req: NextRequest) {
return apiUser(req, "POST")
}