Skip to content

Commit bf2ccd7

Browse files
committed
Refactored job functions to use readFileSync
1 parent 93b2d8b commit bf2ccd7

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

lib/actions/job.action.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { promises as fs } from "fs";
1+
import { readFileSync } from "fs";
2+
import path from "path";
23

34
import type { GetJobsParams } from "./shared.types";
45

@@ -16,14 +17,12 @@ export async function getJobs(params: GetJobsParams) {
1617
// Calculate the number of jobs to skip based on the page number and page size
1718
const skipAmount = (page - 1) * pageSize;
1819

19-
const file = await fs.readFile(
20-
process.cwd() + "/content/jsearch.json",
21-
"utf8"
22-
);
20+
const file = path.join(process.cwd(), "content", "jsearch.json");
21+
const fileSync = readFileSync(file, "utf8");
2322

24-
const parsedFile = JSON.parse(file);
23+
const jsonData = JSON.parse(fileSync);
2524

26-
const allJobs = parsedFile?.data || [];
25+
const allJobs = jsonData.data || [];
2726

2827
const searchQueryRegExp = new RegExp(
2928
(searchQuery || "").toLowerCase(),
@@ -83,14 +82,12 @@ export async function getJobs(params: GetJobsParams) {
8382

8483
export async function getCountryFilters() {
8584
try {
86-
const file = await fs.readFile(
87-
process.cwd() + "/content/countries.json",
88-
"utf8"
89-
);
85+
const file = path.join(process.cwd(), "content", "countries.json");
86+
const fileSync = readFileSync(file, "utf8");
9087

91-
const parsedFile = JSON.parse(file);
88+
const jsonData = JSON.parse(fileSync);
9289

93-
const result = parsedFile.map((country: any) => ({
90+
const result = jsonData.map((country: any) => ({
9491
name: country.name,
9592
value: country.cca2,
9693
}));

0 commit comments

Comments
 (0)