upd: announcement
Deskripsi: - pembatasan pengumuman - fix get all 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 _ from "lodash";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
@@ -30,7 +31,7 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
},
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const announcement = await prisma.announcement.findUnique({
|
||||
where: {
|
||||
@@ -126,6 +127,9 @@ export async function DELETE(request: Request, context: { params: { id: string }
|
||||
},
|
||||
});
|
||||
|
||||
// create log user
|
||||
const log = await createLogUser({ act: 'DELETE', desc: 'User menghapus data pengumuman', table: 'announcement', data: id })
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
@@ -206,11 +210,14 @@ export async function PUT(request: Request, context: { params: { id: string } })
|
||||
data: memberDivision,
|
||||
});
|
||||
|
||||
return NextResponse.json({ success: true, message: "Berhasil mengedit pengumuman" }, { status: 200 });
|
||||
// create log user
|
||||
const log = await createLogUser({ act: 'UPDATE', desc: 'User mengupdate data pengumuman', table: 'announcement', data: id })
|
||||
|
||||
return NextResponse.json({ success: true, message: "Berhasil mengupdate pengumuman" }, { status: 200 });
|
||||
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return NextResponse.json({ success: false, message: "Gagal mengedit pengumuman, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
|
||||
return NextResponse.json({ success: false, message: "Gagal mengeupdate pengumuman, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Group } from '@mantine/core';
|
||||
import { prisma } from "@/module/_global";
|
||||
import { funGetUserByCookies } from "@/module/auth";
|
||||
import _ from "lodash";
|
||||
import moment from "moment";
|
||||
import "moment/locale/id";
|
||||
import { NextResponse } from "next/server";
|
||||
import { createLogUser } from '@/module/user';
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
@@ -19,17 +19,63 @@ export async function GET(request: Request) {
|
||||
}
|
||||
|
||||
const villageId = user.idVillage
|
||||
const roleUser = user.idUserRole
|
||||
const groupId = user.idGroup
|
||||
const { searchParams } = new URL(request.url);
|
||||
const name = searchParams.get('search');
|
||||
const announcements = await prisma.announcement.findMany({
|
||||
where: {
|
||||
idVillage: String(villageId),
|
||||
isActive: true,
|
||||
title: {
|
||||
contains: (name == undefined || name == null) ? "" : name,
|
||||
mode: "insensitive"
|
||||
|
||||
let kondisi: any = {
|
||||
idVillage: String(villageId),
|
||||
isActive: true,
|
||||
title: {
|
||||
contains: (name == undefined || name == null) ? "" : name,
|
||||
mode: "insensitive"
|
||||
}
|
||||
}
|
||||
|
||||
if (roleUser != "supadmin") {
|
||||
if (roleUser == "cosupadmin" || roleUser == "admin") {
|
||||
kondisi = {
|
||||
idVillage: String(villageId),
|
||||
isActive: true,
|
||||
title: {
|
||||
contains: (name == undefined || name == null) ? "" : name,
|
||||
mode: "insensitive"
|
||||
},
|
||||
AnnouncementMember: {
|
||||
some: {
|
||||
idGroup: String(groupId)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
} else {
|
||||
kondisi = {
|
||||
idVillage: String(villageId),
|
||||
isActive: true,
|
||||
title: {
|
||||
contains: (name == undefined || name == null) ? "" : name,
|
||||
mode: "insensitive"
|
||||
},
|
||||
AnnouncementMember: {
|
||||
some: {
|
||||
idGroup: String(groupId),
|
||||
Division: {
|
||||
DivisionMember: {
|
||||
some: {
|
||||
idUser: String(user.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const announcements = await prisma.announcement.findMany({
|
||||
where: kondisi,
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
@@ -98,6 +144,9 @@ export async function POST(request: Request) {
|
||||
data: memberDivision,
|
||||
});
|
||||
|
||||
// create log user
|
||||
const log = await createLogUser({ act: 'CREATE', desc: 'User membuat data pengumuman baru', table: 'announcement', data: data.id })
|
||||
|
||||
return NextResponse.json({ success: true, message: "Berhasil membuat pengumuman" }, { status: 200 });
|
||||
|
||||
} catch (error) {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { funGetUserByCookies } from "@/module/auth";
|
||||
import { revalidatePath, revalidateTag } from "next/cache";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
@@ -11,13 +10,24 @@ export async function GET(request: Request) {
|
||||
if (user.id == undefined) {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||
}
|
||||
|
||||
const role = user.idUserRole
|
||||
const villaId = user.idVillage
|
||||
const data = await prisma.group.findMany({
|
||||
where: {
|
||||
const group = user.idGroup
|
||||
let kondisi: any = {
|
||||
isActive: true,
|
||||
idVillage: String(villaId)
|
||||
}
|
||||
|
||||
if (role != "supadmin") {
|
||||
kondisi = {
|
||||
isActive: true,
|
||||
idVillage: String(villaId)
|
||||
},
|
||||
idVillage: String(villaId),
|
||||
id: String(group)
|
||||
}
|
||||
}
|
||||
|
||||
const data = await prisma.group.findMany({
|
||||
where: kondisi,
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
|
||||
Reference in New Issue
Block a user