Compare commits

...

2 Commits

Author SHA1 Message Date
nabillah
5287fb90bf Mobile API Admin: Main dashboard, User Access, Super admin
Add:
- api/mobile/admin/

### No Issue
2025-10-14 17:31:53 +08:00
nabillah
51c70ef98a chore(release): 1.5.1 2025-10-14 10:43:21 +08:00
5 changed files with 206 additions and 1 deletions

View File

@@ -2,6 +2,8 @@
All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
## [1.5.1](https://wibugit.wibudev.com/bip/hipmi/compare/v1.5.0...v1.5.1) (2025-10-14)
## 1.5.0 (2025-10-09)

View File

@@ -1,6 +1,6 @@
{
"name": "hipmi",
"version": "1.5.0",
"version": "1.5.1",
"private": true,
"prisma": {
"seed": "bun prisma/seed.ts"

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,
},
);
}
}