diff --git a/src/app/api/mobile/division/[id]/route.ts b/src/app/api/mobile/division/[id]/route.ts index 546d602..8c5e884 100644 --- a/src/app/api/mobile/division/[id]/route.ts +++ b/src/app/api/mobile/division/[id]/route.ts @@ -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"; @@ -82,13 +82,15 @@ export async function GET(request: Request, context: { params: { id: string } }) // EDIT DATA DIVISI 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 { id } = context.params; + const { name, desc, 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 { name, desc } = (await request.json()); + const data = await prisma.division.count({ where: { id: id, @@ -101,7 +103,7 @@ export async function PUT(request: Request, context: { params: { id: string } }) success: false, message: "Edit divisi gagal, data tidak ditemukan", }, - { status: 404 } + { status: 200 } ); } @@ -116,7 +118,7 @@ export async function PUT(request: Request, context: { params: { id: string } }) }); // create log user - const log = await createLogUser({ act: 'UPDATE', desc: 'User mengupdate data divisi', table: 'division', data: id }) + const log = await createLogUserMobile({ act: 'UPDATE', desc: 'User mengupdate data divisi', table: 'division', data: id, user: userMobile.id }) return NextResponse.json( { diff --git a/src/app/api/mobile/division/[id]/status/route.ts b/src/app/api/mobile/division/[id]/status/route.ts index 6e17164..57193aa 100644 --- a/src/app/api/mobile/division/[id]/status/route.ts +++ b/src/app/api/mobile/division/[id]/status/route.ts @@ -1,16 +1,18 @@ import { prisma } from "@/module/_global"; -import { funGetUserByCookies } from "@/module/auth"; -import { createLogUser } from "@/module/user"; +import { funGetUserById } from "@/module/auth"; +import { createLogUserMobile } from "@/module/user"; import { NextResponse } from "next/server"; 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 { isActive } = (await request.json()); + const { isActive, 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 data = await prisma.division.count({ where: { id: id, @@ -23,7 +25,7 @@ export async function POST(request: Request, context: { params: { id: string } } success: false, message: "Edit status divisi gagal, data tidak ditemukan", }, - { status: 404 } + { status: 200 } ); } @@ -37,7 +39,7 @@ export async function POST(request: Request, context: { params: { id: string } } }); // create log user - const log = await createLogUser({ act: 'UPDATE', desc: 'User mengedit status data divisi', table: 'division', data: id }) + const log = await createLogUserMobile({ act: 'UPDATE', desc: 'User mengedit status data divisi', table: 'division', data: id, user: userMobile.id }) return NextResponse.json({ success: true, message: "Status divisi berhasil diupdate", }, { status: 200 });