API Mobile

Add: Api event

### No Isuue
This commit is contained in:
2025-09-12 15:59:12 +08:00
parent 80537f5ea5
commit 2a0455f601
3 changed files with 219 additions and 6 deletions

View File

@@ -1,8 +1,8 @@
import { NextResponse } from "next/server";
import prisma from "@/lib/prisma";
import _ from "lodash";
import { NextResponse } from "next/server";
export { GET, PUT };
export { DELETE, GET, PUT };
async function GET(request: Request, { params }: { params: { id: string } }) {
try {
@@ -31,10 +31,14 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
},
},
authorId: true,
Author: {
include: {
Profile: true,
},
},
},
});
return NextResponse.json(
{
success: true,
@@ -75,8 +79,6 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
},
});
console.log("[UPDATE]", update);
return NextResponse.json(
{
success: true,
@@ -95,3 +97,35 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
);
}
}
async function DELETE(
request: Request,
{ params }: { params: { id: string } }
) {
try {
const { id } = params;
const deleteData = await prisma.event.delete({
where: {
id: id,
},
});
return NextResponse.json(
{
success: true,
message: "Delete berhasil",
},
{ status: 200 }
);
} catch (error) {
return NextResponse.json(
{
success: false,
message: "Delete gagal",
reason: (error as Error).message,
},
{ status: 500 }
);
}
}