upd: pembatasan user
Deskripsi: - menyimpan role pada variable global - pembatasan pada position - pembatasan pada fitur home - memasang log user pada position No Issues
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { funGetUserByCookies } from "@/module/auth";
|
||||
import { createLogUser } from "@/module/user";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
@@ -80,6 +81,8 @@ export async function DELETE(request: Request, context: { params: { id: string }
|
||||
},
|
||||
});
|
||||
|
||||
// create log user
|
||||
const log = await createLogUser({ act: 'UPDATE', desc: 'User mengupdate status data jabatan', table: 'position', data: id })
|
||||
return NextResponse.json(
|
||||
{ success: true, message: "Berhasil mengubah status jabatan" },
|
||||
{ status: 200 }
|
||||
@@ -104,8 +107,12 @@ export async function PUT(request: Request, context: { params: { id: string } })
|
||||
where: {
|
||||
name: data.name,
|
||||
idGroup: data.idGroup,
|
||||
NOT: {
|
||||
id: id
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
if (cek == 0) {
|
||||
const positions = await prisma.position.update({
|
||||
where: {
|
||||
@@ -113,10 +120,13 @@ export async function PUT(request: Request, context: { params: { id: string } })
|
||||
},
|
||||
data: {
|
||||
name: data.name,
|
||||
idGroup: data.idGroup,
|
||||
// idGroup: data.idGroup,
|
||||
},
|
||||
});
|
||||
return NextResponse.json({ success: true, message: "Berhasil mengedit jabatan", positions, }, { status: 200 });
|
||||
|
||||
// create log user
|
||||
const log = await createLogUser({ act: 'UPDATE', desc: 'User mengupdate data jabatan', table: 'position', data: id })
|
||||
return NextResponse.json({ success: true, message: "Berhasil mengedit jabatan", }, { status: 200 });
|
||||
} else {
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Jabatan sudah ada" },
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { funGetUserByCookies } from "@/module/auth";
|
||||
import { createLogUser } from "@/module/user";
|
||||
import _ from "lodash";
|
||||
import { revalidatePath, revalidateTag } from "next/cache";
|
||||
import { NextResponse } from "next/server";
|
||||
@@ -21,9 +22,9 @@ export async function GET(request: Request) {
|
||||
|
||||
if (idGroup == "null" || idGroup == undefined) {
|
||||
grup = user.idGroup
|
||||
} else {
|
||||
} else {
|
||||
grup = idGroup
|
||||
}
|
||||
}
|
||||
|
||||
const cek = await prisma.group.count({
|
||||
where: {
|
||||
@@ -36,10 +37,20 @@ export async function GET(request: Request) {
|
||||
return NextResponse.json({ success: false, message: "Gagal mendapatkan jabatan, data tidak ditemukan", }, { status: 404 });
|
||||
}
|
||||
|
||||
const filter = await prisma.group.findUnique({
|
||||
where: {
|
||||
id: grup
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
name: true
|
||||
}
|
||||
})
|
||||
|
||||
const positions = await prisma.position.findMany({
|
||||
where: {
|
||||
idGroup: grup,
|
||||
isActive: (active == "true" ? true : false),
|
||||
isActive: active == 'false' ? false : true,
|
||||
name: {
|
||||
contains: (name == undefined || name == null) ? "" : name,
|
||||
mode: "insensitive"
|
||||
@@ -62,7 +73,7 @@ export async function GET(request: Request) {
|
||||
group: v.Group.name
|
||||
}))
|
||||
|
||||
return NextResponse.json({ success: true, message: "Berhasil mendapatkan jabatan", data: allData, }, { status: 200 });
|
||||
return NextResponse.json({ success: true, message: "Berhasil mendapatkan jabatan", data: allData, filter }, { status: 200 });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return NextResponse.json({ success: false, message: "Gagal mendapatkan jabatan, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
|
||||
@@ -78,18 +89,26 @@ export async function POST(request: Request) {
|
||||
if (user.id == undefined) {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||
}
|
||||
const data = await request.json();
|
||||
const { name, idGroup } = await request.json();
|
||||
|
||||
let groupFix = idGroup
|
||||
|
||||
if (groupFix == null || groupFix == undefined || groupFix == "") {
|
||||
groupFix = user.idGroup
|
||||
}
|
||||
|
||||
|
||||
const cek = await prisma.position.count({
|
||||
where: {
|
||||
name: data.name,
|
||||
idGroup: data.idGroup,
|
||||
name: name,
|
||||
idGroup: groupFix,
|
||||
},
|
||||
});
|
||||
if (cek == 0) {
|
||||
const positions = await prisma.position.create({
|
||||
data: {
|
||||
name: data.name,
|
||||
idGroup: data.idGroup,
|
||||
name: name,
|
||||
idGroup: groupFix,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
@@ -102,6 +121,9 @@ export async function POST(request: Request) {
|
||||
revalidatePath('/position?active=true', 'page')
|
||||
revalidateTag('position')
|
||||
|
||||
// create log user
|
||||
const log = await createLogUser({ act: 'CREATE', desc: 'User membuat data jabatan baru', table: 'position', data: positions.id })
|
||||
|
||||
return NextResponse.json({ success: true, message: "Berhasil menambahkan jabatan", positions, }, { status: 200 });
|
||||
} else {
|
||||
return NextResponse.json(
|
||||
|
||||
Reference in New Issue
Block a user