req: pengumuman

Deskripsi:
- struktur db pengumuman
- api tambah pengumuman
- api detail pengumuman
- api update pengumuman

No Issues
This commit is contained in:
2026-01-14 15:02:43 +08:00
parent 3d2a35446c
commit 9f3acf306e
4 changed files with 107 additions and 12 deletions

View File

@@ -1,4 +1,4 @@
import { funSendWebPush, prisma } from "@/module/_global";
import { DIR, funSendWebPush, funUploadFile, prisma } from "@/module/_global";
import { funGetUserById } from "@/module/auth";
import { createLogUserMobile } from '@/module/user';
import _ from "lodash";
@@ -113,7 +113,12 @@ export async function GET(request: Request) {
// CREATE PENGUMUMAN
export async function POST(request: Request) {
try {
const { title, desc, groups, user } = (await request.json());
const body = await request.formData()
const dataBody = body.get("data")
const cekFile = body.has("file0")
// const { title, desc, groups, user } = (await request.json());
const { title, desc, groups, user } = JSON.parse(dataBody as string)
const userMobile = await funGetUserById({ id: String(user) })
if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") {
@@ -152,6 +157,29 @@ export async function POST(request: Request) {
}
}
if (cekFile) {
body.delete("data")
for (var pair of body.entries()) {
if (String(pair[0]).substring(0, 4) == "file") {
const file = body.get(pair[0]) as File
const fExt = file.name.split(".").pop()
const fName = decodeURIComponent(file.name.replace("." + fExt, ""))
const upload = await funUploadFile({ file: file, dirId: DIR.announcement })
if (upload.success) {
await prisma.announcementFile.create({
data: {
idStorage: upload.data.id,
idAnnouncement: data.id,
name: fName,
extension: String(fExt)
}
})
}
}
}
}
const announcementMember = await prisma.announcementMember.createMany({
data: memberDivision,
});