deskrispi:
- fix status job
This commit is contained in:
2025-02-19 16:22:34 +08:00
parent 758d4b4a9e
commit d474d7611b
15 changed files with 412 additions and 166 deletions

View File

@@ -0,0 +1,87 @@
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
import backendLogger from "@/util/backendLogger";
import _ from "lodash";
import { redirect } from "next/navigation";
import { NextResponse } from "next/server";
export async function GET(
request: Request,
{ params }: { params: { name: string } }
) {
try {
let fixData;
const { name } = params;
const { searchParams } = new URL(request.url);
const page = searchParams.get("page");
const takeData = 10
const skipData = Number(page) * takeData - takeData;
const userLoginId = await funGetUserIdByToken();
if (!userLoginId) {
return NextResponse.json(
{
success: false,
message: "Gagal mendapatkan data",
reason: "Unauthorized",
},
{
status: 401,
}
);
}
if (!page) {
fixData = await prisma.job.findMany({
orderBy: {
updatedAt: "desc",
},
where: {
authorId: userLoginId,
isActive: true,
isArsip: false,
},
include: {
Author: true,
MasterStatus: true,
},
});
} else {
const fixStatusName = _.startCase(name);
fixData = await prisma.job.findMany({
take: takeData,
skip: skipData,
orderBy: {
updatedAt: "desc",
},
where: {
authorId: userLoginId,
isActive: true,
MasterStatus: {
name: fixStatusName || name,
},
},
include: {
Author: true,
MasterStatus: true,
},
});
}
return NextResponse.json({
success: true,
message: "Berhasil mendapatkan data",
data: fixData,
});
} catch (error) {
backendLogger.error("Error Get Data Job", error);
return NextResponse.json(
{
success: false,
message: "Gagal mendapatkan data",
reason: (error as Error).message,
},
{ status: 500 }
);
}
}

View File

@@ -2,22 +2,12 @@ import { Job_Status } from "@/app_modules/job";
import { job_funGetAllByStatusId } from "@/app_modules/job/fun";
import { job_funGetMasterStatus } from "@/app_modules/job/fun/get/get_master_status";
export default async function Page({ params }: { params: { id: string } }) {
let statusId = params.id;
export default async function Page() {
const dataJob = await job_funGetAllByStatusId({
page: 1,
statusId: statusId,
});
const listStatus = await job_funGetMasterStatus();
return (
<>
<Job_Status
statusId={statusId}
dataJob={dataJob}
listStatus={listStatus as any}
/>
<Job_Status/>
</>
);
}