Compare commits
2 Commits
mobile-api
...
mobile-api
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5287fb90bf | ||
|
|
51c70ef98a |
@@ -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)
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hipmi",
|
||||
"version": "1.5.0",
|
||||
"version": "1.5.1",
|
||||
"private": true,
|
||||
"prisma": {
|
||||
"seed": "bun prisma/seed.ts"
|
||||
|
||||
39
src/app/api/mobile/admin/main-dashboard/route.ts
Normal file
39
src/app/api/mobile/admin/main-dashboard/route.ts
Normal 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,
|
||||
});
|
||||
}
|
||||
}
|
||||
87
src/app/api/mobile/admin/user/[id]/route.ts
Normal file
87
src/app/api/mobile/admin/user/[id]/route.ts
Normal 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,
|
||||
});
|
||||
}
|
||||
}
|
||||
77
src/app/api/mobile/admin/user/route.ts
Normal file
77
src/app/api/mobile/admin/user/route.ts
Normal 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,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user