upd: api mobile

Deskripsi:
- update edit profile

No Issues
This commit is contained in:
amel
2025-06-16 17:39:17 +08:00
parent 8fe18dace8
commit 524fda814d

View File

@@ -1,6 +1,6 @@
import { DIR, funDeleteFile, funUploadFile, prisma } from "@/module/_global";
import { funGetUserByCookies } from "@/module/auth";
import { createLogUser } from "@/module/user";
import { funGetUserByCookies, funGetUserById } from "@/module/auth";
import { createLogUserMobile } from "@/module/user";
import _ from "lodash";
import { NextResponse } from "next/server";
import sharp from "sharp";
@@ -38,8 +38,8 @@ export async function GET(request: Request) {
name: true
}
},
UserRole:{
select:{
UserRole: {
select: {
name: true
}
}
@@ -65,16 +65,16 @@ export async function GET(request: Request) {
// UPDATE PROFILE BY COOKIES
export async function PUT(request: Request) {
try {
const user = await funGetUserByCookies()
if (user.id == undefined) {
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
}
const body = await request.formData()
const file = body.get("file") as File;
const data = body.get("data");
const { name, email, phone, nik, gender, idPosition } = JSON.parse(data as string)
const { name, email, phone, nik, gender, idPosition, id } = JSON.parse(data as string)
const user = await funGetUserById({ id: String(id) })
if (user.id == "null" || user.id == undefined || user.id == "") {
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
}
const cekNIK = await prisma.user.count({
where: {
@@ -104,7 +104,7 @@ export async function PUT(request: Request) {
});
if (cekNIK > 0 || cekEmail > 0 || cekPhone > 0) {
return NextResponse.json({ success: false, message: "Gagal ubah profile, NIK/email/phone sudah terdaftar" }, { status: 401 });
return NextResponse.json({ success: false, message: "Gagal ubah profile, NIK/email/phone sudah terdaftar" }, { status: 200 });
}
const update = await prisma.user.update({
@@ -158,7 +158,7 @@ export async function PUT(request: Request) {
}
const log = await createLogUser({ act: 'UPDATE', desc: 'User mengupdate data profile', table: 'user', data: user.id })
const log = await createLogUserMobile({ act: 'UPDATE', desc: 'User mengupdate data profile', table: 'user', data: user.id, user: user.id })
return NextResponse.json({ success: true, message: "Berhasil ubah profile" });
} catch (error) {