Merge pull request #129 from bipproduction/lukman/19-agustus-2024

feat : update history
This commit is contained in:
Amalia
2024-08-19 17:44:27 +08:00
committed by GitHub
14 changed files with 385 additions and 222 deletions

View File

@@ -151,13 +151,15 @@ export async function DELETE(request: Request, context: { params: { id: string }
// EDIT CALENDER BY ID
export async function PUT(request: Request, context: { params: { id: string } }) {
try {
console.log('amalai')
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 userId = user.id
const { title, desc, timeStart, dateStart, timeEnd, linkMeet, repeatEventTyper, member } = await request.json()
const cek = await prisma.divisionCalendar.count({
@@ -166,6 +168,8 @@ export async function PUT(request: Request, context: { params: { id: string } })
}
})
console.log(id, title, desc, timeStart, dateStart, timeEnd, linkMeet, repeatEventTyper, member)
if (cek == 0) {
return NextResponse.json(
{
@@ -176,6 +180,11 @@ export async function PUT(request: Request, context: { params: { id: string } })
);
}
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 statusCalender = 0
const data = await prisma.divisionCalendar.update({
where: {
id: id
@@ -183,15 +192,17 @@ export async function PUT(request: Request, context: { params: { id: string } })
data: {
title: title,
desc: desc,
timeStart: timeStart,
dateStart: dateStart,
timeEnd: timeEnd,
createdBy: String(userId),
timeStart: timeStartFix,
dateStart: new Date(dateStart),
timeEnd: timeEndFix,
linkMeet: linkMeet,
repeatEventTyper: repeatEventTyper
repeatEventTyper: repeatEventTyper,
status: statusCalender
}
});
await prisma.divisionCalendarMember.deleteMany({
const del = await prisma.divisionCalendarMember.deleteMany({
where: {
idCalendar: id
}
@@ -207,6 +218,8 @@ export async function PUT(request: Request, context: { params: { id: string } })
data: omitMember
});
console.log(omitMember)
return NextResponse.json({ success: true, message: "Berhasil mengedit calender" }, { status: 200 });

View File

@@ -0,0 +1,82 @@
import moment from "moment";
import { NextResponse } from "next/server";
import "moment/locale/id";
import { funGetUserByCookies } from "@/module/auth";
import { prisma } from "@/module/_global";
import _ from "lodash";
// GET HSITORY
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 { searchParams } = new URL(request.url);
const idDivision = searchParams.get("division");
if (idDivision != "null" && idDivision != null && idDivision != undefined) {
const cekDivision = await prisma.division.count({
where: {
id: idDivision,
isActive: true
}
})
if (cekDivision == 0) {
return NextResponse.json({ success: false, message: "Gagal mendapatkan divisi, data tidak ditemukan" }, { status: 404 });
}
const data = await prisma.divisionCalendar.findMany({
where: {
isActive: true,
idDivision: idDivision,
},
select: {
id: true,
title: true,
timeStart: true,
dateStart: true,
timeEnd: true,
},
orderBy: [
{
dateStart: 'asc'
},
{
timeStart: 'asc'
},
{
timeEnd: 'asc'
}
]
});
const allOmit = data.map((v: any) => ({
..._.omit(v, ["title", "timeStart", "timeEnd", "id", ]),
dateStart: v.dateStart,
data: [
{
id: v.id,
title: v.title,
timeEnd: moment.utc(v.timeEnd).format('HH:mm'),
timeStart: moment.utc(v.timeStart).format('HH:mm')
}
]
}))
return NextResponse.json({ success: true, message: "Berhasil mendapatkan calender", data: allOmit }, { status: 200 });
} else {
return NextResponse.json({ success: false, message: "Gagal mendapatkan calender, data tidak ditemukan" }, { status: 404 });
}
} catch (error) {
console.log(error)
return NextResponse.json({ success: false, message: "Gagal mendapatkan calender, data tidak ditemukan" }, { status: 404 });
}
}