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 { prisma } from "@/module/_global";
|
||||||
import { funGetUserByCookies, funGetUserById } from "@/module/auth";
|
import { funGetUserById } from "@/module/auth";
|
||||||
import { createLogUser } from "@/module/user";
|
import { createLogUserMobile } from "@/module/user";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
@@ -99,11 +99,14 @@ export async function GET(request: Request, context: { params: { id: string } })
|
|||||||
// HAPUS PENGUMUMAN
|
// HAPUS PENGUMUMAN
|
||||||
export async function DELETE(request: Request, context: { params: { id: string } }) {
|
export async function DELETE(request: Request, context: { params: { id: string } }) {
|
||||||
try {
|
try {
|
||||||
const user = await funGetUserByCookies()
|
const { id } = context.params
|
||||||
if (user.id == undefined) {
|
const { user } = (await request.json());
|
||||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
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({
|
const data = await prisma.announcement.count({
|
||||||
where: {
|
where: {
|
||||||
id: id,
|
id: id,
|
||||||
@@ -116,7 +119,7 @@ export async function DELETE(request: Request, context: { params: { id: string }
|
|||||||
success: false,
|
success: false,
|
||||||
message: "Hapus pengumuman gagal, data tidak ditemukan",
|
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
|
// 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(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
success: true,
|
success: true,
|
||||||
message: "Pengumuman berhasil dihapus",
|
message: "Pengumuman berhasil dihapus",
|
||||||
data,
|
|
||||||
},
|
},
|
||||||
{ status: 200 }
|
{ status: 200 }
|
||||||
);
|
);
|
||||||
@@ -151,14 +153,13 @@ export async function DELETE(request: Request, context: { params: { id: string }
|
|||||||
// EDIT PENGUMUMAN
|
// EDIT PENGUMUMAN
|
||||||
export async function PUT(request: Request, context: { params: { id: string } }) {
|
export async function PUT(request: Request, context: { params: { id: string } }) {
|
||||||
try {
|
try {
|
||||||
const user = await funGetUserByCookies();
|
const { title, desc, groups, user } = (await request.json());
|
||||||
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 { id } = context.params;
|
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({
|
const data = await prisma.announcement.count({
|
||||||
where: {
|
where: {
|
||||||
@@ -213,7 +214,7 @@ export async function PUT(request: Request, context: { params: { id: string } })
|
|||||||
});
|
});
|
||||||
|
|
||||||
// create log user
|
// 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 });
|
return NextResponse.json({ success: true, message: "Berhasil mengupdate pengumuman" }, { status: 200 });
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user