upd: global admin
Deskripsi: - variable global untuk task NO Issues
This commit is contained in:
12
src/app/(application)/division/[id]/layout.tsx
Normal file
12
src/app/(application)/division/[id]/layout.tsx
Normal file
@@ -0,0 +1,12 @@
|
||||
import { WrapLayoutDivision } from "@/module/division_new";
|
||||
import _ from "lodash"
|
||||
|
||||
export default async function Layout({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<>
|
||||
<WrapLayoutDivision>
|
||||
{children}
|
||||
</WrapLayoutDivision>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { funGetUserByCookies } from "@/module/auth";
|
||||
import { createLogUser } from "@/module/user";
|
||||
import _ from "lodash";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
@@ -43,14 +44,11 @@ export async function POST(request: Request, context: { params: { id: string } }
|
||||
})
|
||||
}
|
||||
|
||||
// create log user
|
||||
const log = await createLogUser({ act: 'CREATE', desc: 'User menambahkan anggota tugas divisi', table: 'divisionProject', data: id })
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Berhasil menambahkan anggota tugas",
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
|
||||
return NextResponse.json( { success: true, message: "Berhasil menambahkan anggota tugas", }, { status: 200 } );
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return NextResponse.json({ success: false, message: "Gagal menambah anggota tugas, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
|
||||
@@ -92,14 +90,10 @@ export async function DELETE(request: Request, context: { params: { id: string }
|
||||
}
|
||||
})
|
||||
|
||||
// create log user
|
||||
const log = await createLogUser({ act: 'DELETE', desc: 'User mengeluarkan anggota dari tugas divisi', table: 'divisionProject', data: id })
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Berhasil mengeluarkan anggota",
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
return NextResponse.json( { success: true, message: "Berhasil mengeluarkan anggota", }, { status: 200 } );
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return NextResponse.json({ success: false, message: "Gagal mengeluarkan anggota, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { funGetUserByCookies } from "@/module/auth";
|
||||
import { createLogUser } from "@/module/user";
|
||||
import _ from "lodash";
|
||||
import moment from "moment";
|
||||
import "moment/locale/id"
|
||||
@@ -184,16 +185,15 @@ export async function POST(request: Request, context: { params: { id: string } }
|
||||
dateStart: new Date(moment(dateStart).format('YYYY-MM-DD')),
|
||||
dateEnd: new Date(moment(dateEnd).format('YYYY-MM-DD')),
|
||||
},
|
||||
select: {
|
||||
id: true
|
||||
}
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Detail tugas berhasil ditambahkan",
|
||||
data,
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
// create log user
|
||||
const log = await createLogUser({ act: 'CREATE', desc: 'User menambahkan detail tugas divisi', table: 'divisionProjectTask', data: create.id })
|
||||
|
||||
return NextResponse.json({ success: true, message: "Detail tugas berhasil ditambahkan", data, }, { status: 200 });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return NextResponse.json({ success: false, message: "Gagal mengedit detail tugas, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
|
||||
@@ -238,13 +238,10 @@ export async function DELETE(request: Request, context: { params: { id: string }
|
||||
}
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Tugas berhasil dibatalkan",
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
// create log user
|
||||
const log = await createLogUser({ act: 'UPDATE', desc: 'User membatalkan tugas divisi', table: 'divisionProject', data: id })
|
||||
|
||||
return NextResponse.json({ success: true, message: "Tugas berhasil dibatalkan", }, { status: 200 });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return NextResponse.json({ success: false, message: "Gagal membatalkan tugas, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
|
||||
@@ -287,13 +284,10 @@ export async function PUT(request: Request, context: { params: { id: string } })
|
||||
}
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Tugas berhasil diedit",
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
// create log user
|
||||
const log = await createLogUser({ act: 'UPDATE', desc: 'User mengupdate data tugas divisi', table: 'divisionProject', data: id })
|
||||
|
||||
return NextResponse.json( { success: true, message: "Tugas berhasil diedit", }, { status: 200 } );
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return NextResponse.json({ success: false, message: "Gagal mengedit tugas, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { funGetUserByCookies } from "@/module/auth";
|
||||
import { createLogUser } from "@/module/user";
|
||||
import _ from "lodash";
|
||||
import moment from "moment";
|
||||
import { NextResponse } from "next/server";
|
||||
@@ -67,14 +68,10 @@ export async function DELETE(request: Request, context: { params: { id: string }
|
||||
}
|
||||
})
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Tugas berhasil dihapus",
|
||||
data,
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
// create log user
|
||||
const log = await createLogUser({ act: 'DELETE', desc: 'User menghapus detail task divisi', table: 'divisionProjectTask', data: id })
|
||||
|
||||
return NextResponse.json({ success: true, message: "Tugas berhasil dihapus", data, }, { status: 200 });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return NextResponse.json({ success: false, message: "Gagal menghapus tugas divisi, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
|
||||
@@ -146,14 +143,10 @@ export async function PUT(request: Request, context: { params: { id: string } })
|
||||
}
|
||||
})
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Status detail tugas berhasil diupdate",
|
||||
data,
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
// create log user
|
||||
const log = await createLogUser({ act: 'UPDATE', desc: 'User mengupdate status detail task divisi', table: 'divisionProjectTask', data: id })
|
||||
|
||||
return NextResponse.json({ success: true, message: "Status detail tugas berhasil diupdate", data, }, { status: 200 });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return NextResponse.json({ success: false, message: "Gagal mengupdate status detail tugas, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
|
||||
@@ -230,14 +223,10 @@ export async function POST(request: Request, context: { params: { id: string } }
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Detail tugas berhasil diedit",
|
||||
data,
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
// create log user
|
||||
const log = await createLogUser({ act: 'UPDATE', desc: 'User mengupdate data detail task divisi', table: 'divisionProjectTask', data: id })
|
||||
|
||||
return NextResponse.json({ success: true, message: "Detail tugas berhasil diedit", data, }, { status: 200 });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return NextResponse.json({ success: false, message: "Gagal mengedit detail tugas, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
|
||||
|
||||
@@ -4,6 +4,7 @@ import _ from "lodash";
|
||||
import { NextResponse } from "next/server";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { createLogUser } from "@/module/user";
|
||||
|
||||
// HAPUS DETAIL FILE, HAPUS FILE DI ASSETS DAN DATABASE (BUKAN PAKE ISACTIVE)
|
||||
export async function DELETE(request: Request, context: { params: { id: string } }) {
|
||||
@@ -55,15 +56,10 @@ export async function DELETE(request: Request, context: { params: { id: string }
|
||||
},
|
||||
});
|
||||
|
||||
// create log user
|
||||
const log = await createLogUser({ act: 'DELETE', desc: 'User menghpus file divisi', table: 'divisionProject', data: String(dataRelasi?.idProject) })
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "File berhasil dihapus",
|
||||
data,
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
return NextResponse.json({ success: true, message: "File berhasil dihapus", data, }, { status: 200 });
|
||||
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
@@ -155,7 +151,8 @@ export async function POST(request: Request, context: { params: { id: string } }
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// create log user
|
||||
const log = await createLogUser({ act: 'CREATE', desc: 'User meambahkan file tugas divisi baru', table: 'divisionProject', data: id })
|
||||
return NextResponse.json({ success: true, message: "Berhasil membuat tugas divisi" }, { status: 200 });
|
||||
|
||||
} catch (error) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import { NextResponse } from "next/server";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
import moment from "moment";
|
||||
import { createLogUser } from "@/module/user";
|
||||
|
||||
|
||||
// GET ALL DATA TUGAS DIVISI
|
||||
@@ -196,6 +197,9 @@ export async function POST(request: Request) {
|
||||
})
|
||||
}
|
||||
|
||||
// create log user
|
||||
const log = await createLogUser({ act: 'CREATE', desc: 'User membuat tugas divisi baru', table: 'divisionProject', data: data.id })
|
||||
|
||||
|
||||
return NextResponse.json({ success: true, message: "Berhasil membuat tugas divisi" }, { status: 200 });
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@ import EditDivision from './ui/edit_division';
|
||||
import CreateReport from './ui/create_report';
|
||||
import ReportDivisionId from './ui/report_division_id';
|
||||
import { funGetDivisionById, funGetListDivisionByIdDivision, funGetSearchMemberDivision } from './lib/api_division';
|
||||
import { globalIsAdminDivision } from './lib/val_division';
|
||||
import WrapLayoutDivision from './ui/wrap_division';
|
||||
|
||||
export { CreateUsers };
|
||||
export { CreateAdminDivision };
|
||||
@@ -34,4 +36,6 @@ export { CreateReport }
|
||||
export { ReportDivisionId }
|
||||
export { funGetDivisionById }
|
||||
export { funGetListDivisionByIdDivision }
|
||||
export { funGetSearchMemberDivision }
|
||||
export { funGetSearchMemberDivision }
|
||||
export { globalIsAdminDivision }
|
||||
export { WrapLayoutDivision }
|
||||
@@ -1,4 +1,5 @@
|
||||
import { hookstate } from "@hookstate/core";
|
||||
import { IFormMemberDivision } from "./type_division";
|
||||
|
||||
export const globalMemberDivision = hookstate<IFormMemberDivision[]>([]);
|
||||
export const globalMemberDivision = hookstate<IFormMemberDivision[]>([]);
|
||||
export const globalIsAdminDivision = hookstate<boolean>(false)
|
||||
28
src/module/division_new/ui/wrap_division.tsx
Normal file
28
src/module/division_new/ui/wrap_division.tsx
Normal file
@@ -0,0 +1,28 @@
|
||||
'use client'
|
||||
import { useHookstate } from "@hookstate/core";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { globalIsAdminDivision } from "../lib/val_division";
|
||||
import { funGetDivisionById } from "../lib/api_division";
|
||||
import { useParams } from "next/navigation";
|
||||
import { funGetUserByCookies } from "@/module/auth";
|
||||
|
||||
export default function WrapLayoutDivision({ children }: { children: React.ReactNode }) {
|
||||
const isAdmin = useHookstate(globalIsAdminDivision)
|
||||
const param = useParams<{ id: string }>()
|
||||
|
||||
const getData = async () => {
|
||||
const res = await funGetDivisionById(param.id);
|
||||
const login = await funGetUserByCookies()
|
||||
const cek = res.data.member.some((i: any) => i.idUser == login.id && i.isAdmin == true)
|
||||
isAdmin.set(cek)
|
||||
}
|
||||
|
||||
useShallowEffect(() => {
|
||||
getData()
|
||||
}, [])
|
||||
return (
|
||||
<>
|
||||
{children}
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user