Skip to content

Commit

Permalink
feat:added expiry date feature (#497)
Browse files Browse the repository at this point in the history
* feat:added expiry date feature

* feat: some style change

* fix:typo error

* feat: added logic to run cron job

* feat: ui change for the calender

---------

Co-authored-by: Rohan <[email protected]>
  • Loading branch information
Paribesh01 and Rohan authored Oct 16, 2024
1 parent f186265 commit 5b24e29
Show file tree
Hide file tree
Showing 9 changed files with 252 additions and 6 deletions.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@
"@types/lodash": "^4.17.7",
"@types/uuid": "^10.0.0",
"@uidotdev/usehooks": "^2.4.1",
"100xdevs-job-board": "file:",
"bcryptjs": "^2.4.3",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"cmdk": "^1.0.0",
"date-fns": "^2.30.0",
"dayjs": "^1.11.13",
"framer-motion": "^11.9.0",
"jiti": "^1.21.6",
Expand All @@ -71,6 +73,7 @@
"node-cron": "^3.0.3",
"nodemailer": "^6.9.15",
"react": "^18",
"react-day-picker": "^8.10.1",
"react-dom": "^18",
"react-hook-form": "^7.52.2",
"react-icons": "^5.2.1",
Expand All @@ -86,6 +89,7 @@
"devDependencies": {
"@types/bcryptjs": "^2.4.6",
"@types/node": "^20.16.10",
"@types/node-cron": "^3.0.11",
"@types/nodemailer": "^6.4.16",
"@types/react": "^18",
"@types/react-dom": "^18",
Expand All @@ -102,4 +106,4 @@
"ts-node": "^10.9.2",
"typescript": "^5.6.2"
}
}
}
3 changes: 3 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ model Job {
application String
companyLogo String
skills String[]
expired Boolean @default(false)
hasExpiryDate Boolean @default(false) @map("has_expiry_date")
expiryDate DateTime?
hasSalaryRange Boolean @default(false) @map("has_salary_range")
minSalary Int?
maxSalary Int?
Expand Down
23 changes: 22 additions & 1 deletion prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ let jobs = [
maxExperience: 2,
companyLogo: '',
hasSalaryRange: true,
hasExpiryDate: true,
expiryDate: new Date(new Date().setDate(new Date().getDate() + 49)),
minSalary: 60000,
maxSalary: 80000,
isVerifiedJob: true,
Expand All @@ -53,7 +55,8 @@ let jobs = [
type: EmployementType.Full_time,
workMode: WorkMode.office,
currency: Currency.USD,

hasExpiryDate: true,
expiryDate: new Date(new Date().setDate(new Date().getDate() + 49)),
hasExperiencerange: false,
companyLogo: '',
hasSalaryRange: false,
Expand All @@ -74,6 +77,7 @@ let jobs = [
type: EmployementType.Full_time,
workMode: WorkMode.hybrid,
currency: Currency.USD,
hasExpiryDate: false,
hasExperiencerange: true,
minExperience: 3,
maxExperience: 4,
Expand All @@ -100,6 +104,8 @@ let jobs = [
hasExperiencerange: true,
minExperience: 1,
maxExperience: 2,
hasExpiryDate: true,
expiryDate: new Date(new Date().setDate(new Date().getDate() + 49)),
companyLogo: '',
hasSalaryRange: true,
minSalary: 50000,
Expand All @@ -120,6 +126,8 @@ let jobs = [
type: EmployementType.Full_time,
workMode: WorkMode.hybrid,
currency: Currency.USD,
hasExpiryDate: true,
expiryDate: new Date(new Date().setDate(new Date().getDate() + 49)),
hasExperiencerange: false,
companyLogo: '',
hasSalaryRange: true,
Expand All @@ -145,6 +153,8 @@ let jobs = [
minExperience: 1,
maxExperience: 2,
companyLogo: '',
hasExpiryDate: true,
expiryDate: new Date(new Date().setDate(new Date().getDate() + 49)),
hasSalaryRange: true,
minSalary: 80000,
maxSalary: 100000,
Expand All @@ -165,6 +175,7 @@ let jobs = [
workMode: WorkMode.remote,
currency: Currency.USD,
hasExperiencerange: true,
hasExpiryDate: false,
minExperience: 1,
maxExperience: 2,
companyLogo: '',
Expand All @@ -187,6 +198,8 @@ let jobs = [
workMode: WorkMode.hybrid,
currency: Currency.USD,
hasExperiencerange: true,
hasExpiryDate: true,
expiryDate: new Date(new Date().setDate(new Date().getDate() + 49)),
minExperience: 1,
maxExperience: 2,
companyLogo: '',
Expand All @@ -208,6 +221,7 @@ let jobs = [
workMode: WorkMode.office,
currency: Currency.USD,
hasExperiencerange: true,
hasExpiryDate: false,
minExperience: 1,
maxExperience: 2,
companyLogo: '',
Expand All @@ -233,6 +247,8 @@ let jobs = [
minExperience: 1,
maxExperience: 2,
companyLogo: '',
hasExpiryDate: true,
expiryDate: new Date(new Date().setDate(new Date().getDate() + 49)),
hasSalaryRange: true,
minSalary: 75000,
maxSalary: 95000,
Expand All @@ -253,6 +269,7 @@ let jobs = [
currency: Currency.USD,
companyLogo: '',
hasSalaryRange: true,
hasExpiryDate: false,
hasExperiencerange: false,
minSalary: 25000,
maxSalary: 50000,
Expand All @@ -271,6 +288,8 @@ let jobs = [
type: EmployementType.Contract,
workMode: WorkMode.remote,
currency: Currency.USD,
hasExpiryDate: true,
expiryDate: new Date(new Date().setDate(new Date().getDate() + 49)),
hasExperiencerange: true,
minExperience: 1,
maxExperience: 2,
Expand Down Expand Up @@ -339,6 +358,8 @@ async function seedJobs() {
city: faker.location.city(),
address: faker.location.city(),
hasExperiencerange: j.hasExperiencerange,
hasExpiryDate: j.hasExpiryDate,
expiryDate: j.expiryDate,
minExperience: j.minExperience,
maxExperience: j.maxExperience,
companyLogo: '/main.svg',
Expand Down
20 changes: 20 additions & 0 deletions src/actions/corn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// lib/cron.ts
import cron from 'node-cron';
import { updateExpiredJobs } from './job.action';

let cronJobInitialized = false;

export const startCronJob = () => {
if (!cronJobInitialized) {
cronJobInitialized = true;

// Schedule the job to run at midnight (12:00 AM) every day
cron.schedule('0 0 * * *', async () => {
try {
await updateExpiredJobs();
} catch (error) {
console.error('Error updating expired jobs:', error);
}
});
}
};
33 changes: 31 additions & 2 deletions src/actions/job.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export const createJob = withServerActionAsyncCatcher<
description,
hasSalaryRange,
hasExperiencerange,
hasExpiryDate,
expiryDate,
maxSalary,
minExperience,
maxExperience,
Expand All @@ -65,6 +67,8 @@ export const createJob = withServerActionAsyncCatcher<
description,
hasExperiencerange,
minExperience,
expiryDate,
hasExpiryDate,
maxExperience,
skills,
companyName,
Expand Down Expand Up @@ -111,6 +115,7 @@ export const getAllJobs = withServerActionAsyncCatcher<
orderBy: [orderBy],
where: {
isVerifiedJob: true,
expired: false,
...filterQueries,
},
select: {
Expand All @@ -124,6 +129,8 @@ export const getAllJobs = withServerActionAsyncCatcher<
hasExperiencerange: true,
minExperience: true,
maxExperience: true,
hasExpiryDate: true,
expiryDate: true,
skills: true,
address: true,
workMode: true,
Expand Down Expand Up @@ -164,6 +171,7 @@ export const getRecommendedJobs = withServerActionAsyncCatcher<
category: category,
id: { not: id },
isVerifiedJob: true,
expired: false,
},
orderBy: {
postedAt: 'desc',
Expand Down Expand Up @@ -194,6 +202,7 @@ export const getRecommendedJobs = withServerActionAsyncCatcher<
const fallbackJobs = await prisma.job.findMany({
where: {
id: { not: id },
expired: false,
},
orderBy: {
postedAt: 'desc',
Expand Down Expand Up @@ -239,7 +248,7 @@ export const getJobById = withServerActionAsyncCatcher<
const result = JobByIdSchema.parse(data);
const { id } = result;
const job = await prisma.job.findFirst({
where: { id },
where: { id, expired: false },
select: {
id: true,
title: true,
Expand All @@ -252,6 +261,8 @@ export const getJobById = withServerActionAsyncCatcher<
category: true,
city: true,
hasExperiencerange: true,
expiryDate: true,
hasExpiryDate: true,
minExperience: true,
maxExperience: true,
skills: true,
Expand All @@ -272,6 +283,7 @@ export const getJobById = withServerActionAsyncCatcher<
export const getCityFilters = async () => {
const response = await prisma.job.findMany({
select: {
expired: false,
city: true,
},
});
Expand All @@ -284,8 +296,9 @@ export const getCityFilters = async () => {
export const getRecentJobs = async () => {
try {
const recentJobs = await prisma.job.findMany({
where: {
where: {
isVerifiedJob: true,
expired: false,
},
orderBy: {
postedAt: 'desc',
Expand Down Expand Up @@ -354,3 +367,19 @@ export const updateJob = withServerActionAsyncCatcher<
additonal
).serialize();
});

export async function updateExpiredJobs() {
const currentDate = new Date();

await prisma.job.updateMany({
where: {
hasExpiryDate: true,
expiryDate: {
lt: currentDate,
},
},
data: {
expired: true,
},
});
}
2 changes: 2 additions & 0 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { startCronJob } from '@/actions/corn';
import Faqs from '@/components/Faqs';
import HeroSection from '@/components/hero-section';
import { JobLanding } from '@/components/job-landing';
import Testimonials from '@/components/Testimonials';

const HomePage = async () => {
startCronJob();
return (
<div>
<HeroSection />
Expand Down
Loading

0 comments on commit 5b24e29

Please sign in to comment.