rev: calender

Deskripsi:
- check jika ada acara di tgl yg sama di beda divisi 1 grup

No Issues
This commit is contained in:
amel
2025-01-07 17:16:12 +08:00
parent 9e8bf1c73b
commit e4f631e397
3 changed files with 114 additions and 15 deletions

View File

@@ -193,4 +193,44 @@ export async function POST(request: Request) {
console.error(error);
return NextResponse.json({ success: false, message: "Gagal membuat acara kalender, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
}
}
// CEK TGL AVAILABLE
export async function PUT(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 { idDivision, title, desc, timeStart, timeEnd, dateStart, dateEnd, repeatEventTyper, member, linkMeet, repeatValue } = (await request.json());
const division = await prisma.division.findUnique({
where: {
id: idDivision
}
})
const cek = await prisma.divisionCalendarReminder.count({
where: {
isActive: true,
dateStart: new Date(dateStart),
Division: {
idGroup: division?.idGroup
}
}
})
if (cek > 0) {
return NextResponse.json({ success: false, message: "Tidak dapat membuat acara kalender, acara kalender sudah ada pada tanggal tersebut" }, { status: 400 });
} else {
return NextResponse.json({ success: true, message: "Berhasil membuat acara kalender" }, { status: 200 });
}
} catch (error) {
console.error(error)
return NextResponse.json({ success: false, message: "Gagal membuat acara kalender, coba lagi nanti (error: 500)" }, { status: 404 });
}
}