Merge pull request #71 from bipproduction/lukman/29-juli-2024
Lukman/29 juli 2024
This commit is contained in:
21
api.http
21
api.http
@@ -164,3 +164,24 @@ Content-Type: application/json
|
|||||||
"id": "clz6dq88e0001b3mlyl4vjaf8"
|
"id": "clz6dq88e0001b3mlyl4vjaf8"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
###
|
||||||
|
POST http://localhost:3000/api/announcement/post?path=create-announcement HTTP/1.1
|
||||||
|
Content-Type: application/json
|
||||||
|
|
||||||
|
{
|
||||||
|
"title": "cobaannouncement1",
|
||||||
|
"desc": "coba announcement",
|
||||||
|
"idVillage": "121212",
|
||||||
|
"createBy": "111",
|
||||||
|
"groups": [
|
||||||
|
{
|
||||||
|
"idGroup": "1",
|
||||||
|
"idDivision": "1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idGroup": "1",
|
||||||
|
"idDivision": "2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { apiAnnouncement } from "@/module/announcement";
|
import { apiAnnouncement } from "@/module/announcement";
|
||||||
|
import { NextRequest } from "next/server";
|
||||||
|
|
||||||
export async function GET(req: Request) {
|
export async function GET(req: NextRequest) {
|
||||||
return apiAnnouncement(req, "GET")
|
return apiAnnouncement(req, "GET")
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import { apiAnnouncement } from "@/module/announcement";
|
import { apiAnnouncement } from "@/module/announcement";
|
||||||
|
import { NextRequest } from "next/server";
|
||||||
|
|
||||||
export async function POST(req: Request) {
|
export async function POST(req: NextRequest) {
|
||||||
return apiAnnouncement(req, "POST");
|
return apiAnnouncement(req, "POST");
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
|
import { NextRequest } from "next/server";
|
||||||
import { API_INDEX_ANNOUNCEMENT } from "./api_index";
|
import { API_INDEX_ANNOUNCEMENT } from "./api_index";
|
||||||
|
|
||||||
type Method = "GET" | "POST";
|
type Method = "GET" | "POST";
|
||||||
export async function apiAnnouncement(req: Request, method: Method) {
|
export async function apiAnnouncement(req: NextRequest, method: Method) {
|
||||||
const { searchParams } = new URL(req.url);
|
const { searchParams } = new URL(req.url);
|
||||||
const path = searchParams.get("path");
|
const path = searchParams.get("path");
|
||||||
const act = API_INDEX_ANNOUNCEMENT.find(
|
const act = API_INDEX_ANNOUNCEMENT.find(
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
export async function getAllAnnouncement(req: Request) {
|
import { NextRequest } from "next/server";
|
||||||
|
|
||||||
|
export async function getAllAnnouncement(req: NextRequest) {
|
||||||
try {
|
try {
|
||||||
|
return Response.json({
|
||||||
|
success: true,
|
||||||
|
});
|
||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
export async function getOneAnnouncement(req: Request) {
|
import { prisma } from "@/module/_global";
|
||||||
try {
|
import { NextRequest } from "next/server";
|
||||||
} catch (error) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
export async function getOneAnnouncement(req: NextRequest) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,44 @@
|
|||||||
export async function createAnnouncement(req: Request) {
|
import { prisma } from "@/module/_global";
|
||||||
try {
|
import { NextRequest } from "next/server";
|
||||||
} catch (error) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
export async function createAnnouncement(req: NextRequest) {
|
||||||
|
try {
|
||||||
|
const data = await req.json();
|
||||||
|
const announcement = await prisma.annoucement.create({
|
||||||
|
data: {
|
||||||
|
title: data.title,
|
||||||
|
desc: data.desc,
|
||||||
|
idVillage: data.idVillage,
|
||||||
|
createdBy: data.createBy,
|
||||||
|
isActive: true,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
title: true,
|
||||||
|
desc: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const dataMember = data.groups.map((group: any) => ({
|
||||||
|
idAnnoucement: announcement.id,
|
||||||
|
idGroup: group.idGroup,
|
||||||
|
idDivision: group.idDivision,
|
||||||
|
isActive: true,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const announcementMember = await prisma.annoucementMember.createMany({
|
||||||
|
data: dataMember,
|
||||||
|
});
|
||||||
|
|
||||||
|
return Response.json({
|
||||||
|
announcement: announcement,
|
||||||
|
announcementMember: announcementMember,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
return Response.json(
|
||||||
|
{ message: "Internal Server Error", success: false },
|
||||||
|
{ status: 500 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
export async function deleteAnnouncement(req: Request) {
|
import { NextRequest } from "next/server";
|
||||||
|
|
||||||
|
export async function deleteAnnouncement(req: NextRequest) {
|
||||||
try {
|
try {
|
||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
export async function updateAnnouncement(req: Request) {
|
import { NextRequest } from "next/server";
|
||||||
|
|
||||||
|
export async function updateAnnouncement(req: NextRequest) {
|
||||||
try {
|
try {
|
||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user