upd: api mobile
Deskripsi: - update mobile api member diskusi umum No Issues
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { prisma } from "@/module/_global";
|
import { prisma } from "@/module/_global";
|
||||||
import { funGetUserByCookies } from "@/module/auth";
|
import { funGetUserByCookies, funGetUserById } from "@/module/auth";
|
||||||
import { createLogUser } from "@/module/user";
|
import { createLogUser, createLogUserMobile } from "@/module/user";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
@@ -53,13 +53,14 @@ export async function POST(request: Request, context: { params: { id: string } }
|
|||||||
// MENGELUARKAN ANGGOTA
|
// MENGELUARKAN ANGGOTA
|
||||||
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()
|
|
||||||
if (user.id == undefined) {
|
|
||||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
|
||||||
}
|
|
||||||
|
|
||||||
const { id } = context.params
|
const { id } = context.params
|
||||||
const { idUser } = (await request.json());
|
const { idUser, 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 cek = await prisma.discussion.count({
|
const cek = await prisma.discussion.count({
|
||||||
@@ -70,7 +71,7 @@ export async function DELETE(request: Request, context: { params: { id: string }
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (cek == 0) {
|
if (cek == 0) {
|
||||||
return NextResponse.json({ success: false, message: "Gagal, data tidak ditemukan" }, { status: 404 });
|
return NextResponse.json({ success: false, message: "Gagal, data tidak ditemukan" }, { status: 200 });
|
||||||
}
|
}
|
||||||
|
|
||||||
const deleteMember = await prisma.discussionMember.deleteMany({
|
const deleteMember = await prisma.discussionMember.deleteMany({
|
||||||
@@ -81,7 +82,7 @@ export async function DELETE(request: Request, context: { params: { id: string }
|
|||||||
})
|
})
|
||||||
|
|
||||||
// create log user
|
// create log user
|
||||||
const log = await createLogUser({ act: 'DELETE', desc: 'User mengeluarkan anggota diskusi umum', table: 'discussion', data: String(id) })
|
const log = await createLogUserMobile({ act: 'DELETE', desc: 'User mengeluarkan anggota diskusi umum', table: 'discussion', data: String(id), user: userMobile.id })
|
||||||
|
|
||||||
return NextResponse.json({ success: true, message: "Berhasil mengeluarkan anggota diskusi umum" }, { status: 200 });
|
return NextResponse.json({ success: true, message: "Berhasil mengeluarkan anggota diskusi umum" }, { status: 200 });
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user