Merge pull request #459 from bipproduction/amalia/16-jun-25
upd: api mobile
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { DIR, funDeleteFile, funUploadFile, prisma } from "@/module/_global";
|
import { DIR, funDeleteFile, funUploadFile, prisma } from "@/module/_global";
|
||||||
import { funGetUserByCookies } from "@/module/auth";
|
import { funGetUserByCookies, funGetUserById } from "@/module/auth";
|
||||||
import { createLogUser } from "@/module/user";
|
import { createLogUserMobile } from "@/module/user";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import sharp from "sharp";
|
import sharp from "sharp";
|
||||||
@@ -38,8 +38,8 @@ export async function GET(request: Request) {
|
|||||||
name: true
|
name: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
UserRole:{
|
UserRole: {
|
||||||
select:{
|
select: {
|
||||||
name: true
|
name: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -65,16 +65,16 @@ export async function GET(request: Request) {
|
|||||||
// UPDATE PROFILE BY COOKIES
|
// UPDATE PROFILE BY COOKIES
|
||||||
export async function PUT(request: Request) {
|
export async function PUT(request: Request) {
|
||||||
try {
|
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 body = await request.formData()
|
||||||
const file = body.get("file") as File;
|
const file = body.get("file") as File;
|
||||||
const data = body.get("data");
|
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({
|
const cekNIK = await prisma.user.count({
|
||||||
where: {
|
where: {
|
||||||
@@ -104,7 +104,7 @@ export async function PUT(request: Request) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (cekNIK > 0 || cekEmail > 0 || cekPhone > 0) {
|
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({
|
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" });
|
return NextResponse.json({ success: true, message: "Berhasil ubah profile" });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user