API Dashboard Admin Table JOB

This commit is contained in:
2025-02-06 17:31:09 +08:00
parent f27a900604
commit be318e7136
14 changed files with 809 additions and 487 deletions

View File

@@ -0,0 +1,112 @@
import { Job_Status } from '@/app_modules/job';
import { prisma } from "@/app/lib";
import _, { take } from "lodash";
import { NextResponse } from "next/server";
import backendLogger from '@/util/backendLogger';
import moment from 'moment';
export async function GET(request: Request, { params }: {
params: { status: string }
}
) {
const method = request.method;
if (method !== 'GET') {
return NextResponse.json({
success: false,
message: "Method not allowed"
},
{ status: 405 }
)
}
const { status } = params;
const { searchParams } = new URL(request.url);
const search = searchParams.get("search");
const page = searchParams.get("page");
const takeData = 10
const skipData = Number(page) * takeData - takeData;
try {
let fixData;
const fixStatus = _.startCase(status);
if (!page) {
fixData = await prisma.job.findMany({
orderBy: {
updatedAt: "desc"
},
where: {
isActive: true,
isArsip: false,
MasterStatus: {
name: fixStatus
},
title: {
contains: search ? search : "",
mode: "insensitive"
}
},
include: {
Author: true,
},
})
} else {
fixData = await prisma.job.findMany({
take: takeData,
skip: skipData,
orderBy: {
updatedAt: "desc"
},
where: {
isActive: true,
isArsip: false,
MasterStatus: {
name: fixStatus
},
title: {
contains: search ? search : "",
mode: "insensitive"
}
},
include: {
Author: true,
},
})
const nCount = await prisma.job.count({
where: {
isActive: true,
isArsip: false,
title: {
contains: search ? search : "",
mode: "insensitive"
}
}
})
fixData = {
data: fixData,
nPage: _.ceil(nCount / takeData)
}
}
return NextResponse.json({
success: true,
message: "Data found",
data: fixData,
},
{ status: 200 }
)
} catch (error) {
backendLogger.error("Eror get data", error)
return NextResponse.json({
success: false,
message: "Data not found",
reason: (error as Error).message
},
{ status: 500 }
)
}
}

View File

@@ -0,0 +1,109 @@
import { prisma } from "@/app/lib";
import _ from "lodash";
import moment from "moment";
import { NextResponse } from "next/server";
export async function GET(request: Request,
{ params }: { params: { status: string } }
) {
const method = request.method;
if (method !== "GET") {
return NextResponse.json({
success: false,
message: "Method not allowed"
},
{ status: 405 }
)
}
const { status } = params;
const { searchParams } = new URL(request.url);
const search = searchParams.get("search");
const page = searchParams.get("page");
const takeData = 10;
const skipData = Number(page) * takeData - takeData;
try {
let fixData;
const fixStatus = _.startCase(status);
if (!page && !search) {
fixData = await prisma.voting.findMany({
orderBy: {
updatedAt: "desc"
},
where: {
isActive: true,
isArsip: false,
Voting_Status: {
name: fixStatus
}
},
include: {
Author: {
select: {
id: true,
username: true,
Profile: {
select: {
name: true
}
}
}
},
Voting_Status: true,
Voting_Kontributor: true,
Voting_DaftarNamaVote: true,
}
})
} else if (!page && search) {
fixData = await prisma.voting.findMany({
orderBy: {
updatedAt: "desc"
},
where: {
isActive: true,
isArsip: false,
Voting_Status: {
name: fixStatus
},
title: {
contains: search,
mode: "insensitive"
}
},
include: {
Author: {
select: {
id: true,
username: true,
Profile: {
select: {
name: true
}
}
}
},
Voting_Status: true,
Voting_Kontributor: true,
Voting_DaftarNamaVote: true,
}
})
} else if (page && !search) {
if (fixStatus === "Publish") {
const getAllData = await prisma.voting.findMany({
where: {
isActive: true,
Voting_Status: {
name: fixStatus
},
isArsip: false
}
});
}
}
} catch (error) {
}
}