upd: api mobile
Deskripsi: - update load divisi - tambah anggota - hapus anggota - update status admin divisi - info divisi - detail divisi No Issues
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { prisma } from "@/module/_global";
|
import { prisma } from "@/module/_global";
|
||||||
import { funGetUserByCookies } from "@/module/auth";
|
import { funGetUserById } from "@/module/auth";
|
||||||
import { createLogUser } from "@/module/user";
|
import { createLogUserMobile } 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";
|
||||||
@@ -12,12 +12,13 @@ export async function GET(request: Request, context: { params: { id: string } })
|
|||||||
try {
|
try {
|
||||||
let allData
|
let allData
|
||||||
const { id } = context.params;
|
const { id } = context.params;
|
||||||
const user = await funGetUserByCookies()
|
|
||||||
const { searchParams } = new URL(request.url);
|
const { searchParams } = new URL(request.url);
|
||||||
const kategori = searchParams.get("cat");
|
const kategori = searchParams.get("cat");
|
||||||
|
const user = searchParams.get("user");
|
||||||
|
const userMobile = await funGetUserById({ id: String(user) })
|
||||||
|
|
||||||
if (user.id == undefined) {
|
if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") {
|
||||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await prisma.division.findUnique({
|
const data = await prisma.division.findUnique({
|
||||||
@@ -28,7 +29,7 @@ export async function GET(request: Request, context: { params: { id: string } })
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
return NextResponse.json({ success: false, message: "Gagal mendapatkan divisi, data tidak ditemukan", }, { status: 404 });
|
return NextResponse.json({ success: false, message: "Gagal mendapatkan divisi, data tidak ditemukan", }, { status: 200 });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kategori == "jumlah") {
|
if (kategori == "jumlah") {
|
||||||
@@ -244,18 +245,17 @@ export async function GET(request: Request, context: { params: { id: string } })
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// MENGELUARKAN ANGGOTA DARI DIVISI
|
// MENGELUARKAN ANGGOTA DARI DIVISI
|
||||||
export async function DELETE(request: Request, context: { params: { id: string } }) {
|
export async function DELETE(request: Request, context: { params: { id: string } }) {
|
||||||
try {
|
try {
|
||||||
const user = await funGetUserByCookies()
|
const idDivision = context.params.id
|
||||||
if (user.id == undefined) {
|
const { id, user } = (await request.json())
|
||||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
|
||||||
}
|
|
||||||
|
|
||||||
const idDivision = context.params.id;
|
const userMobile = await funGetUserById({ id: String(user) })
|
||||||
const { id } = (await request.json());
|
|
||||||
|
if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") {
|
||||||
|
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
|
||||||
|
}
|
||||||
|
|
||||||
const data = await prisma.division.count({
|
const data = await prisma.division.count({
|
||||||
where: {
|
where: {
|
||||||
@@ -270,7 +270,7 @@ export async function DELETE(request: Request, context: { params: { id: string }
|
|||||||
success: false,
|
success: false,
|
||||||
message: "Hapus anggota divisi gagal, data tidak ditemukan",
|
message: "Hapus anggota divisi gagal, data tidak ditemukan",
|
||||||
},
|
},
|
||||||
{ status: 404 }
|
{ status: 200 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,7 +281,7 @@ export async function DELETE(request: Request, context: { params: { id: string }
|
|||||||
});
|
});
|
||||||
|
|
||||||
// create log user
|
// create log user
|
||||||
const log = await createLogUser({ act: 'DELETE', desc: 'User mengeluarkan anggota divisi', table: 'division', data: idDivision })
|
const log = await createLogUserMobile({ act: 'DELETE', desc: 'User mengeluarkan anggota divisi', table: 'division', data: idDivision, user: userMobile.id })
|
||||||
|
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
@@ -300,13 +300,13 @@ export async function DELETE(request: Request, context: { params: { id: string }
|
|||||||
// MENGGANTI STATUS ADMIN DIVISI
|
// MENGGANTI STATUS ADMIN DIVISI
|
||||||
export async function PUT(request: Request, context: { params: { id: string } }) {
|
export async function PUT(request: Request, context: { params: { id: string } }) {
|
||||||
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 idDivision = context.params.id;
|
const idDivision = context.params.id;
|
||||||
const { id, isAdmin } = (await request.json());
|
const { id, isAdmin, user } = (await request.json());
|
||||||
|
const userMobile = await funGetUserById({ id: String(user) })
|
||||||
|
|
||||||
|
if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") {
|
||||||
|
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
|
||||||
|
}
|
||||||
|
|
||||||
const data = await prisma.division.count({
|
const data = await prisma.division.count({
|
||||||
where: {
|
where: {
|
||||||
@@ -321,7 +321,7 @@ export async function PUT(request: Request, context: { params: { id: string } })
|
|||||||
success: false,
|
success: false,
|
||||||
message: "Perubahan status admin gagal, data tidak ditemukan",
|
message: "Perubahan status admin gagal, data tidak ditemukan",
|
||||||
},
|
},
|
||||||
{ status: 404 }
|
{ status: 200 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -335,7 +335,7 @@ export async function PUT(request: Request, context: { params: { id: string } })
|
|||||||
});
|
});
|
||||||
|
|
||||||
// create log user
|
// create log user
|
||||||
const log = await createLogUser({ act: 'UPDATE', desc: 'User mengupdate status anggota divisi', table: 'division', data: idDivision })
|
const log = await createLogUserMobile({ act: 'UPDATE', desc: 'User mengupdate status anggota divisi', table: 'division', data: idDivision, user: userMobile.id })
|
||||||
|
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
@@ -354,13 +354,13 @@ export async function PUT(request: Request, context: { params: { id: string } })
|
|||||||
// TAMBAH ANGGOTA DIVISI
|
// TAMBAH ANGGOTA DIVISI
|
||||||
export async function POST(request: Request, context: { params: { id: string } }) {
|
export async function POST(request: Request, context: { params: { id: string } }) {
|
||||||
try {
|
try {
|
||||||
const user = await funGetUserByCookies()
|
const { member, user } = await request.json()
|
||||||
if (user.id == undefined) {
|
const idDivision = context.params.id
|
||||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
const userMobile = await funGetUserById({ id: String(user) })
|
||||||
}
|
|
||||||
|
|
||||||
const member = await request.json();
|
if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") {
|
||||||
const idDivision = context.params.id;
|
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const data = await prisma.division.count({
|
const data = await prisma.division.count({
|
||||||
@@ -376,7 +376,7 @@ export async function POST(request: Request, context: { params: { id: string } }
|
|||||||
success: false,
|
success: false,
|
||||||
message: "Tambah anggota divisi gagal, data tidak ditemukan",
|
message: "Tambah anggota divisi gagal, data tidak ditemukan",
|
||||||
},
|
},
|
||||||
{ status: 404 }
|
{ status: 200 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -392,7 +392,7 @@ export async function POST(request: Request, context: { params: { id: string } }
|
|||||||
})
|
})
|
||||||
|
|
||||||
// create log user
|
// create log user
|
||||||
const log = await createLogUser({ act: 'CREATE', desc: 'User menambah anggota divisi', table: 'division', data: idDivision })
|
const log = await createLogUserMobile({ act: 'CREATE', desc: 'User menambah anggota divisi', table: 'division', data: idDivision, user: userMobile.id })
|
||||||
|
|
||||||
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) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { prisma } from "@/module/_global";
|
import { prisma } from "@/module/_global";
|
||||||
import { funGetUserByCookies } from "@/module/auth";
|
import { funGetUserByCookies, funGetUserById } from "@/module/auth";
|
||||||
import { createLogUser } from "@/module/user";
|
import { createLogUser } from "@/module/user";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
@@ -9,9 +9,12 @@ import { NextResponse } from "next/server";
|
|||||||
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;
|
||||||
const user = await funGetUserByCookies()
|
const { searchParams } = new URL(request.url);
|
||||||
if (user.id == undefined) {
|
const user = searchParams.get("user");
|
||||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
const userMobile = await funGetUserById({ id: String(user) })
|
||||||
|
|
||||||
|
if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") {
|
||||||
|
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await prisma.division.findUnique({
|
const data = await prisma.division.findUnique({
|
||||||
@@ -22,7 +25,7 @@ export async function GET(request: Request, context: { params: { id: string } })
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
return NextResponse.json({ success: false, message: "Gagal mendapatkan divisi, data tidak ditemukan", }, { status: 404 });
|
return NextResponse.json({ success: false, message: "Gagal mendapatkan divisi, data tidak ditemukan", }, { status: 200 });
|
||||||
}
|
}
|
||||||
|
|
||||||
const member = await prisma.divisionMember.findMany({
|
const member = await prisma.divisionMember.findMany({
|
||||||
@@ -42,9 +45,16 @@ export async function GET(request: Request, context: { params: { id: string } })
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
orderBy: {
|
orderBy: [
|
||||||
isAdmin: 'desc',
|
{
|
||||||
}
|
isAdmin: 'desc',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
User: {
|
||||||
|
name: 'asc'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
const fixMember = member.map((v: any) => ({
|
const fixMember = member.map((v: any) => ({
|
||||||
|
|||||||
@@ -1,26 +1,28 @@
|
|||||||
import { prisma } from "@/module/_global";
|
import { prisma } from "@/module/_global";
|
||||||
import { funGetUserByCookies } from "@/module/auth";
|
import { funGetUserById } from "@/module/auth";
|
||||||
import _, { ceil } from "lodash";
|
import _, { ceil } from "lodash";
|
||||||
import moment from "moment";
|
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
export async function GET(request: Request) {
|
export async function GET(request: Request) {
|
||||||
try {
|
try {
|
||||||
const user = await funGetUserByCookies()
|
|
||||||
const { searchParams } = new URL(request.url)
|
const { searchParams } = new URL(request.url)
|
||||||
const idGroup = searchParams.get("group")
|
const idGroup = searchParams.get("group")
|
||||||
const division = searchParams.get("division")
|
const division = searchParams.get("division")
|
||||||
const date = searchParams.get("date")
|
const date = searchParams.get("date")
|
||||||
const dateAkhir = searchParams.get("date-end")
|
const dateAkhir = searchParams.get("date-end")
|
||||||
const kat = searchParams.get("cat")
|
const kat = searchParams.get("cat")
|
||||||
|
const user = searchParams.get("user")
|
||||||
let grup
|
let grup
|
||||||
|
|
||||||
if (user.id == undefined) {
|
const userMobile = await funGetUserById({ id: String(user) })
|
||||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 })
|
|
||||||
|
if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") {
|
||||||
|
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (idGroup == "null" || idGroup == undefined || idGroup == "") {
|
|
||||||
grup = user.idGroup
|
if (idGroup == "null" || idGroup == undefined || idGroup == "" || idGroup == null || idGroup == "undefined") {
|
||||||
|
grup = userMobile.idGroup
|
||||||
} else {
|
} else {
|
||||||
grup = idGroup
|
grup = idGroup
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user