upd: api mobile
Deskripsi: - update api mobile diskusi umum No Issues
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { funGetUserByCookies, funGetUserById } from "@/module/auth";
|
||||
import { createLogUser, createLogUserMobile } from "@/module/user";
|
||||
import { funGetUserById } from "@/module/auth";
|
||||
import { createLogUserMobile } from "@/module/user";
|
||||
import _ from "lodash";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
@@ -8,14 +8,15 @@ import { NextResponse } from "next/server";
|
||||
// ADD MEMBER DISCUSSION GENERAL
|
||||
export async function POST(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 { member, user } = (await request.json())
|
||||
const userMobile = await funGetUserById({ id: 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 { member } = (await request.json())
|
||||
|
||||
|
||||
const cek = await prisma.discussion.count({
|
||||
where: {
|
||||
id,
|
||||
@@ -24,7 +25,7 @@ export async function POST(request: Request, context: { params: { id: string } }
|
||||
})
|
||||
|
||||
if (cek == 0) {
|
||||
return NextResponse.json({ success: false, message: "Gagal menambahkan anggota, data tidak ditemukan" }, { status: 404 });
|
||||
return NextResponse.json({ success: false, message: "Gagal menambahkan anggota, data tidak ditemukan" }, { status: 200 });
|
||||
}
|
||||
|
||||
if (member.length > 0) {
|
||||
@@ -40,7 +41,7 @@ export async function POST(request: Request, context: { params: { id: string } }
|
||||
}
|
||||
|
||||
// create log user
|
||||
const log = await createLogUser({ act: 'CREATE', desc: 'User menambah anggota diskusi umum', table: 'discussion', data: String(id) })
|
||||
const log = await createLogUserMobile({ act: 'CREATE', desc: 'User menambah anggota diskusi umum', table: 'discussion', data: String(id), user: String(userMobile.id) })
|
||||
return NextResponse.json({ success: true, message: "Berhasil menambahkan anggota diskusi umum" }, { status: 200 });
|
||||
|
||||
} catch (error) {
|
||||
|
||||
@@ -111,7 +111,7 @@ export async function POST(request: Request) {
|
||||
const { idGroup, user, title, desc, member } = await request.json();
|
||||
|
||||
if (user == "null" || user == undefined || user == "") {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
|
||||
}
|
||||
|
||||
const userMobile = await funGetUserById({ id: user })
|
||||
|
||||
Reference in New Issue
Block a user