upd: division

Deskripsi:
- pembatasan user role
- log user

No Issues
This commit is contained in:
amel
2024-09-06 16:48:38 +08:00
parent 73ba6381ff
commit 51b18cd177
5 changed files with 34 additions and 9 deletions

View File

@@ -1,5 +1,6 @@
import { prisma } from "@/module/_global"; import { prisma } from "@/module/_global";
import { funGetUserByCookies } from "@/module/auth"; import { funGetUserByCookies } from "@/module/auth";
import { createLogUser } from "@/module/user";
import _ from "lodash"; import _ from "lodash";
import moment from "moment"; import moment from "moment";
import "moment/locale/id"; import "moment/locale/id";
@@ -195,6 +196,9 @@ export async function DELETE(request: Request, context: { params: { id: string }
}, },
}); });
// create log user
const log = await createLogUser({ act: 'DELETE', desc: 'User mengeluarkan anggota divisi', table: 'division', data: idDivision })
return NextResponse.json( return NextResponse.json(
{ {
success: true, success: true,
@@ -246,6 +250,9 @@ export async function PUT(request: Request, context: { params: { id: string } })
} }
}); });
// create log user
const log = await createLogUser({ act: 'UPDATE', desc: 'User mengupdate status anggota divisi', table: 'division', data: idDivision })
return NextResponse.json( return NextResponse.json(
{ {
success: true, success: true,
@@ -300,6 +307,9 @@ export async function POST(request: Request, context: { params: { id: string } }
data: dataMember data: dataMember
}) })
// create log user
const log = await createLogUser({ act: 'CREATE', desc: 'User menambah anggota divisi', table: 'division', data: idDivision })
return NextResponse.json({ success: true, message: "Berhasil menambahkan anggota divisi" }, { status: 200 }); return NextResponse.json({ success: true, message: "Berhasil menambahkan anggota divisi" }, { status: 200 });
} catch (error) { } catch (error) {
console.error(error); console.error(error);

View File

@@ -1,11 +1,10 @@
// GET MEMBER BY ID
import { prisma } from "@/module/_global"; import { prisma } from "@/module/_global";
import { funGetUserByCookies } from "@/module/auth"; import { funGetUserByCookies } from "@/module/auth";
import _ from "lodash"; import _ from "lodash";
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
// GET MEMBER BY ID
export async function GET(request: Request, context: { params: { id: string } }) { export async function GET(request: Request, context: { params: { id: string } }) {
try { try {
const { id } = context.params; const { id } = context.params;

View File

@@ -1,5 +1,6 @@
import { prisma } from "@/module/_global"; import { prisma } from "@/module/_global";
import { funGetUserByCookies } from "@/module/auth"; import { funGetUserByCookies } from "@/module/auth";
import { createLogUser } from "@/module/user";
import _ from "lodash"; import _ from "lodash";
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
@@ -104,6 +105,9 @@ 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 })
return NextResponse.json( return NextResponse.json(
{ {
success: true, success: true,

View File

@@ -1,5 +1,6 @@
import { prisma } from "@/module/_global"; import { prisma } from "@/module/_global";
import { funGetUserByCookies } from "@/module/auth"; import { funGetUserByCookies } from "@/module/auth";
import { createLogUser } from "@/module/user";
import _ from "lodash"; import _ from "lodash";
import { revalidatePath, revalidateTag } from "next/cache"; import { revalidatePath, revalidateTag } from "next/cache";
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
@@ -140,6 +141,9 @@ export async function POST(request: Request) {
revalidatePath('/divisi', 'page') revalidatePath('/divisi', 'page')
revalidateTag('divisi') revalidateTag('divisi')
// create log user
const log = await createLogUser({ act: 'CREATE', desc: 'User membuat data divisi', table: 'division', data: data.id })
return NextResponse.json({ success: true, message: "Berhasil menambahkan divisi", data, }, { status: 200 }); return NextResponse.json({ success: true, message: "Berhasil menambahkan divisi", data, }, { status: 200 });
} catch (error) { } catch (error) {
console.error(error); console.error(error);

View File

@@ -40,7 +40,7 @@ export default function InformationDivision() {
setName(res.data.division.name); setName(res.data.division.name);
setDeskripsi(res.data.division.desc); setDeskripsi(res.data.division.desc);
setMember(res.data.member) setMember(res.data.member)
const cek = res.data.member.some((i: any) => i.id == login.id && i.isAdmin == true) const cek = res.data.member.some((i: any) => i.idUser == login.id && i.isAdmin == true)
setAdmin(cek) setAdmin(cek)
} else { } else {
toast.error(res.message); toast.error(res.message);
@@ -106,11 +106,14 @@ export default function InformationDivision() {
<Box> <Box>
<LayoutNavbarNew back={"/division/" + param.id} title={name} <LayoutNavbarNew back={"/division/" + param.id} title={name}
menu={ menu={
<ActionIcon variant="light" onClick={() => { ((roleLogin.get() != 'user' && roleLogin.get() != 'coadmin') || isAdmin) ?
router.push('/division/edit/' + param.id) <ActionIcon variant="light" onClick={() => {
}} bg={WARNA.bgIcon} size="lg" radius="lg" aria-label="Settings"> router.push('/division/edit/' + param.id)
<LuClipboardEdit size={20} color='white' /> }} bg={WARNA.bgIcon} size="lg" radius="lg" aria-label="Settings">
</ActionIcon>} <LuClipboardEdit size={20} color='white' />
</ActionIcon>
: <></>
}
/> />
<Box p={20}> <Box p={20}>
<Box> <Box>
@@ -195,7 +198,12 @@ export default function InformationDivision() {
return ( return (
<Box key={i}> <Box key={i}>
<Grid align='center' mt={10} <Grid align='center' mt={10}
onClick={() => { onClickMember(v.id, (v.isAdmin) ? true : false), setChooseMemberName(v.name) }} onClick={() => {
if ((roleLogin.get() != 'user' && roleLogin.get() != 'coadmin') || isAdmin) {
onClickMember(v.id, (v.isAdmin) ? true : false)
setChooseMemberName(v.name)
}
}}
> >
<Grid.Col span={9}> <Grid.Col span={9}>
<Group> <Group>