upd: api mobile

Deskripsi;
- api mobile edit division
- api mobile update status aktive division

No Issues
This commit is contained in:
amel
2025-05-21 17:38:56 +08:00
parent 589fa01bf6
commit 260adf7ee8
2 changed files with 22 additions and 18 deletions

View File

@@ -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(
{

View File

@@ -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 });