rev: calender diviis
Deskripsi: - validasi judul & tgl || tgl & jam nb: blm tampil data yg konflik No Issues
This commit is contained in:
@@ -212,18 +212,85 @@ export async function PUT(request: Request) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const cek = await prisma.divisionCalendarReminder.count({
|
const y = new Date('1970-01-01 ' + timeStart)
|
||||||
|
const x = new Date('1970-01-01 ' + timeEnd)
|
||||||
|
const timeStartFix = new Date(y.getTime() - (y.getTimezoneOffset() * 60000)).toISOString()
|
||||||
|
const timeEndFix = new Date(x.getTime() - (x.getTimezoneOffset() * 60000)).toISOString()
|
||||||
|
|
||||||
|
const cek = await prisma.divisionCalendarReminder.findMany({
|
||||||
where: {
|
where: {
|
||||||
isActive: true,
|
isActive: true,
|
||||||
dateStart: new Date(dateStart),
|
|
||||||
Division: {
|
Division: {
|
||||||
idGroup: division?.idGroup
|
idGroup: division?.idGroup
|
||||||
|
},
|
||||||
|
OR: [
|
||||||
|
{
|
||||||
|
dateStart: new Date(dateStart),
|
||||||
|
DivisionCalendar: {
|
||||||
|
title: {
|
||||||
|
equals: title,
|
||||||
|
mode: "insensitive"
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
dateStart: new Date(dateStart),
|
||||||
|
OR: [
|
||||||
|
{
|
||||||
|
timeStart: { //13:00
|
||||||
|
lte: timeStartFix, //13:30
|
||||||
|
},
|
||||||
|
timeEnd: { //14:00
|
||||||
|
gt: timeStartFix, //13:30
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
timeStart: { //07:00
|
||||||
|
lt: timeEndFix, //07:30
|
||||||
|
},
|
||||||
|
timeEnd: { //08:00
|
||||||
|
gt: timeEndFix, //07:30
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
timeStart: { //07:00
|
||||||
|
gt: timeStartFix, //06:30
|
||||||
|
},
|
||||||
|
timeEnd: { //08:00
|
||||||
|
lte: timeEndFix, //09:30
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
dateStart: true,
|
||||||
|
timeStart: true,
|
||||||
|
timeEnd: true,
|
||||||
|
DivisionCalendar: {
|
||||||
|
select: {
|
||||||
|
title: true,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Division: {
|
||||||
|
select: {
|
||||||
|
name: true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if (cek > 0) {
|
const dataSama = cek.map((v: any) => ({
|
||||||
return NextResponse.json({ success: false, message: "Tidak dapat membuat acara kalender, acara kalender sudah ada pada tanggal tersebut" }, { status: 400 });
|
..._.omit(v, ["DivisionCalendar", "Division"]),
|
||||||
|
title: v.DivisionCalendar.title,
|
||||||
|
divisi: v.Division.name
|
||||||
|
}))
|
||||||
|
|
||||||
|
if (cek.length > 0) {
|
||||||
|
return NextResponse.json({ success: false, message: "Tidak dapat membuat acara kalender, acara kalender sudah ada pada tanggal tersebut", data: dataSama }, { status: 400 });
|
||||||
} else {
|
} else {
|
||||||
return NextResponse.json({ success: true, message: "Berhasil membuat acara kalender" }, { status: 200 });
|
return NextResponse.json({ success: true, message: "Berhasil membuat acara kalender" }, { status: 200 });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user