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 { prisma } from "@/module/_global";
|
||||||
import { funGetUserByCookies, funGetUserById } from "@/module/auth";
|
import { funGetUserById } from "@/module/auth";
|
||||||
import { createLogUser, createLogUserMobile } from "@/module/user";
|
import { createLogUserMobile } from "@/module/user";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
@@ -8,13 +8,14 @@ import { NextResponse } from "next/server";
|
|||||||
// ADD MEMBER DISCUSSION GENERAL
|
// ADD MEMBER DISCUSSION GENERAL
|
||||||
export async function POST(request: Request, context: { params: { id: string } }) {
|
export async function POST(request: Request, context: { params: { id: string } }) {
|
||||||
try {
|
try {
|
||||||
const user = await funGetUserByCookies()
|
const { id } = context.params
|
||||||
if (user.id == undefined) {
|
const { member, user } = (await request.json())
|
||||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
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({
|
const cek = await prisma.discussion.count({
|
||||||
where: {
|
where: {
|
||||||
@@ -24,7 +25,7 @@ export async function POST(request: Request, context: { params: { id: string } }
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (cek == 0) {
|
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) {
|
if (member.length > 0) {
|
||||||
@@ -40,7 +41,7 @@ export async function POST(request: Request, context: { params: { id: string } }
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create log user
|
// 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 });
|
return NextResponse.json({ success: true, message: "Berhasil menambahkan anggota diskusi umum" }, { status: 200 });
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ export async function POST(request: Request) {
|
|||||||
const { idGroup, user, title, desc, member } = await request.json();
|
const { idGroup, user, title, desc, member } = await request.json();
|
||||||
|
|
||||||
if (user == "null" || user == undefined || user == "") {
|
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 })
|
const userMobile = await funGetUserById({ id: user })
|
||||||
|
|||||||
Reference in New Issue
Block a user