Update Versi 1.5.27 #32

Merged
bagasbanuna merged 1009 commits from staging into main 2025-12-17 12:22:28 +08:00
2191 changed files with 98014 additions and 24374 deletions
Showing only changes of commit 5287fb90bf - Show all commits

View File

@@ -0,0 +1,39 @@
import { prisma } from "@/lib";
import { NextResponse } from "next/server";
export async function GET(request: Request) {
let fixDAta;
try {
const user = await prisma.user.count({
where: {
active: true,
},
});
const portofolio = await prisma.portofolio.count({
where: {
active: true,
},
});
fixDAta = {
user: user,
portofolio: portofolio,
};
return NextResponse.json({
status: 200,
success: true,
message: "Success get data main dashboard",
data: fixDAta,
});
} catch (error) {
return NextResponse.json({
status: 500,
success: false,
message: "Error get data main dashboard",
reason: (error as Error).message,
});
}
}

View File

@@ -0,0 +1,87 @@
import { prisma } from "@/lib";
import _ from "lodash";
import { NextResponse } from "next/server";
export { GET, PUT };
async function GET(request: Request, { params }: { params: { id: string } }) {
const { id } = params;
try {
const data = await prisma.user.findUnique({
where: {
id: id,
},
});
return NextResponse.json({
status: 200,
success: true,
message: "Success get data user access",
data: data,
});
} catch (error) {
console.log("[ERROR]", error);
return NextResponse.json({
status: 500,
success: false,
message: "Error get data user access",
reason: (error as Error).message,
});
}
}
async function PUT(request: Request, { params }: { params: { id: string } }) {
const { id } = params;
const { data } = await request.json();
try {
if (data.active) {
const updateData = await prisma.user.update({
where: {
id: id,
},
data: {
active: data.active,
},
});
console.log("[Update Active Berhasil]", updateData);
} else if (data.role) {
const fixName = _.startCase(data.role.replace(/_/g, " "));
const checkRole = await prisma.masterUserRole.findFirst({
where: {
name: fixName,
},
});
console.log("[CHECK ROLE]", checkRole);
const updateData = await prisma.user.update({
where: {
id: id,
},
data: {
masterUserRoleId: checkRole?.id,
},
});
console.log("[Update Role Berhasil]", updateData);
}
return NextResponse.json({
status: 200,
success: true,
message: "Success update data user access",
});
} catch (error) {
console.log("[ERROR]", error);
return NextResponse.json({
status: 500,
success: false,
message: "Error update data user access",
reason: (error as Error).message,
});
}
}

View File

@@ -0,0 +1,77 @@
import { NextResponse } from "next/server";
import { prisma } from "@/lib";
export { GET };
async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const search = searchParams.get("search");
const category = searchParams.get("category");
let fixData;
try {
if(category === "only-user"){
fixData = await prisma.user.findMany({
orderBy: {
updatedAt: "desc",
},
where: {
masterUserRoleId: "1",
username: {
contains: search || "",
mode: "insensitive",
},
},
});
} else if(category === "only-admin"){
fixData = await prisma.user.findMany({
orderBy: {
updatedAt: "desc",
},
where: {
masterUserRoleId: "2",
username: {
contains: search || "",
mode: "insensitive",
},
},
});
} else if (category === "all-role"){
fixData = await prisma.user.findMany({
orderBy: {
updatedAt: "desc",
},
where: {
OR: [
{
masterUserRoleId: "1",
},
{
masterUserRoleId: "2",
}
],
username: {
contains: search || "",
mode: "insensitive",
},
},
});
}
return NextResponse.json({
status: 200,
success: true,
message: "Success get data user access",
data: fixData,
});
} catch (error) {
return NextResponse.json(
{
status: 500,
success: false,
message: "Error get data user access",
reason: (error as Error).message,
},
);
}
}