upd: api mobile
Deskripsi: - edit announcement - delete announcement No Issues
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { funGetUserByCookies, funGetUserById } from "@/module/auth";
|
||||
import { createLogUser } from "@/module/user";
|
||||
import { funGetUserById } from "@/module/auth";
|
||||
import { createLogUserMobile } from "@/module/user";
|
||||
import _ from "lodash";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
@@ -99,11 +99,14 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
// HAPUS PENGUMUMAN
|
||||
export async function DELETE(request: Request, context: { params: { id: string } }) {
|
||||
try {
|
||||
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 { user } = (await request.json());
|
||||
const userMobile = await funGetUserById({ id: String(user) })
|
||||
|
||||
if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
|
||||
}
|
||||
const { id } = context.params;
|
||||
|
||||
const data = await prisma.announcement.count({
|
||||
where: {
|
||||
id: id,
|
||||
@@ -116,7 +119,7 @@ export async function DELETE(request: Request, context: { params: { id: string }
|
||||
success: false,
|
||||
message: "Hapus pengumuman gagal, data tidak ditemukan",
|
||||
},
|
||||
{ status: 404 }
|
||||
{ status: 200 }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -130,13 +133,12 @@ export async function DELETE(request: Request, context: { params: { id: string }
|
||||
});
|
||||
|
||||
// create log user
|
||||
const log = await createLogUser({ act: 'DELETE', desc: 'User menghapus data pengumuman', table: 'announcement', data: id })
|
||||
const log = await createLogUserMobile({ act: 'DELETE', desc: 'User menghapus data pengumuman', table: 'announcement', data: id, user: userMobile.id })
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Pengumuman berhasil dihapus",
|
||||
data,
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
@@ -151,14 +153,13 @@ export async function DELETE(request: Request, context: { params: { id: string }
|
||||
// EDIT PENGUMUMAN
|
||||
export async function PUT(request: Request, context: { params: { id: string } }) {
|
||||
try {
|
||||
const user = await funGetUserByCookies();
|
||||
if (user.id == undefined) {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||
}
|
||||
|
||||
|
||||
const { title, desc, groups } = (await request.json());
|
||||
const { title, desc, groups, user } = (await request.json());
|
||||
const { id } = context.params;
|
||||
const userMobile = await funGetUserById({ id: String(user) })
|
||||
|
||||
if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
|
||||
}
|
||||
|
||||
const data = await prisma.announcement.count({
|
||||
where: {
|
||||
@@ -213,7 +214,7 @@ export async function PUT(request: Request, context: { params: { id: string } })
|
||||
});
|
||||
|
||||
// create log user
|
||||
const log = await createLogUser({ act: 'UPDATE', desc: 'User mengupdate data pengumuman', table: 'announcement', data: id })
|
||||
const log = await createLogUserMobile({ act: 'UPDATE', desc: 'User mengupdate data pengumuman', table: 'announcement', data: id, user: userMobile.id })
|
||||
|
||||
return NextResponse.json({ success: true, message: "Berhasil mengupdate pengumuman" }, { status: 200 });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user