diff --git a/src/app/api/job-posting/disabled/total-posts/route.js b/src/app/api/job-posting/disabled/total-posts/route.js new file mode 100644 index 0000000..4820d98 --- /dev/null +++ b/src/app/api/job-posting/disabled/total-posts/route.js @@ -0,0 +1,22 @@ +import { NextResponse } from 'next/server'; +import { getTotalNumberOfPostings, handleError } from '../../siteRequestUtils'; + +export async function GET() { + try { + const siteCriteria = { site3: true }; + + let jobPostings = await getTotalNumberOfPostings(siteCriteria); + + if (jobPostings < 1) { + return NextResponse.json( + { message: 'Not Found - No job postings found on this page' }, + { status: 404 } + ); + } + + return NextResponse.json({ jobPostings }, { status: 200 }); + } catch (error) { + // Handle errors + return handleError(error); + } +} diff --git a/src/app/api/job-posting/indigenous/total-posts/route.js b/src/app/api/job-posting/indigenous/total-posts/route.js new file mode 100644 index 0000000..feb34dd --- /dev/null +++ b/src/app/api/job-posting/indigenous/total-posts/route.js @@ -0,0 +1,22 @@ +import { NextResponse } from 'next/server'; +import { getTotalNumberOfPostings, handleError } from '../../siteRequestUtils'; + +export async function GET() { + try { + const siteCriteria = { site1: true }; + + let jobPostings = await getTotalNumberOfPostings(siteCriteria); + + if (jobPostings < 1) { + return NextResponse.json( + { message: 'Not Found - No job postings found on this page' }, + { status: 404 } + ); + } + + return NextResponse.json({ jobPostings }, { status: 200 }); + } catch (error) { + // Handle errors + return handleError(error); + } +} diff --git a/src/app/api/job-posting/newcomers/total-posts/route.js b/src/app/api/job-posting/newcomers/total-posts/route.js new file mode 100644 index 0000000..a8dfa9e --- /dev/null +++ b/src/app/api/job-posting/newcomers/total-posts/route.js @@ -0,0 +1,22 @@ +import { NextResponse } from 'next/server'; +import { getTotalNumberOfPostings, handleError } from '../../siteRequestUtils'; + +export async function GET() { + try { + const siteCriteria = { site2: true }; + + let jobPostings = await getTotalNumberOfPostings(siteCriteria); + + if (jobPostings < 1) { + return NextResponse.json( + { message: 'Not Found - No job postings found on this page' }, + { status: 404 } + ); + } + + return NextResponse.json({ jobPostings }, { status: 200 }); + } catch (error) { + // Handle errors + return handleError(error); + } +} diff --git a/src/app/api/job-posting/siteRequestUtils.js b/src/app/api/job-posting/siteRequestUtils.js index f606469..47e2d3a 100644 --- a/src/app/api/job-posting/siteRequestUtils.js +++ b/src/app/api/job-posting/siteRequestUtils.js @@ -3,6 +3,16 @@ import { connectMongoDB } from '@/libs/mongodb'; import posting from '@/app/api/posting'; import mongoose from 'mongoose'; +// Function to get the total number of job postings +export async function getTotalNumberOfPostings(siteCriteria) { + await connectMongoDB(); + + const Posting = mongoose.models.posting || mongoose.model('posting', posting); + const totalNumberOfPostings = await Posting.countDocuments(siteCriteria); + + return totalNumberOfPostings; +} + // Function to extract pagination parameters export function getPaginationParams(req) { const pageSize = 25; diff --git a/src/app/api/job-posting/students/total-posts/route.js b/src/app/api/job-posting/students/total-posts/route.js new file mode 100644 index 0000000..19a7fe9 --- /dev/null +++ b/src/app/api/job-posting/students/total-posts/route.js @@ -0,0 +1,22 @@ +import { NextResponse } from 'next/server'; +import { getTotalNumberOfPostings, handleError } from '../../siteRequestUtils'; + +export async function GET() { + try { + const siteCriteria = { site4: true }; + + let jobPostings = await getTotalNumberOfPostings(siteCriteria); + + if (jobPostings < 1) { + return NextResponse.json( + { message: 'Not Found - No job postings found on this page' }, + { status: 404 } + ); + } + + return NextResponse.json({ jobPostings }, { status: 200 }); + } catch (error) { + // Handle errors + return handleError(error); + } +}