From 0920270f9f459568be7f555da47208508792cbac Mon Sep 17 00:00:00 2001 From: Karthik Surabhi Date: Sun, 15 Sep 2024 19:56:35 -0500 Subject: [PATCH 1/5] seed-cache-review-tags-api --- server/api/review-tags/index.get.ts | 21 +++++++++++++++++++++ server/utils/tasks/seed-cache.ts | 7 ++++++- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 server/api/review-tags/index.get.ts diff --git a/server/api/review-tags/index.get.ts b/server/api/review-tags/index.get.ts new file mode 100644 index 00000000..4e167d34 --- /dev/null +++ b/server/api/review-tags/index.get.ts @@ -0,0 +1,21 @@ +// Import the defineEventHandler function from the 'h3' package +// This is used to create server-side event handlers +import { defineEventHandler } from 'h3'; +import { type ReviewTag } from '../../db/schema'; //import review tags from db schema + +import authenticateAdminRequest from '../../utils/admin'; + +// Define and export the default event handler for this API endpoint +export default defineEventHandler(async (event) => { + // Authenticate the request to ensure it's coming from an admin + // This function should throw an error if authentication fails + + await authenticateAdminRequest(event); + + //RetreiveTags from general memory storage and + //If no tags are found, default to an empty array + const reviewTags = (await general_memoryStorage.getItem('reviewTags')) || []; + + //Return the review tags as the response + return reviewTags; +}); diff --git a/server/utils/tasks/seed-cache.ts b/server/utils/tasks/seed-cache.ts index 9ef9ccb5..8e58f816 100644 --- a/server/utils/tasks/seed-cache.ts +++ b/server/utils/tasks/seed-cache.ts @@ -1,5 +1,5 @@ import { desc, inArray } from 'drizzle-orm'; -import { jobPostingsTable, metaDataTable } from '~~/server/db/schema'; +import { jobPostingsTable, reviewTagsTable, metaDataTable } from '~~/server/db/schema'; //import the review tags table from schema import type { CareerSiteConfig, SEOConfig } from '~~/shared/schemas/setting'; export async function seedCache() { @@ -12,6 +12,10 @@ export async function seedCache() { .from(metaDataTable) .where(inArray(metaDataTable.key, ['seoConfig', 'careerSiteConfig', 'firstSetupAccessKey'])); + //getting the review tags from the reviewTagsTable + const reviewTags = await db.select().from(reviewTagsTable); + console.log(reviewTags); //debug to check the reviewtags response + // Do not save totalApplicants in cache const jobPostings = (await db.select().from(jobPostingsTable).orderBy(desc(jobPostingsTable.createdAt))).map((p) => ({ ...p, @@ -41,6 +45,7 @@ export async function seedCache() { general_memoryStorage.setItem('firstSetupAccessKey', firstSetupAccessKey), general_memoryStorage.setItem('remoteAssetBase', remoteAssetBase), general_memoryStorage.setItem('postings', jobPostings), + general_memoryStorage.setItem('reviewTags', reviewTags), //setting the reviewTags to general_memorystorage ]); return { result: true }; From 2023d7e9683718e8fe8ef2353aaa4766f9e5ef1b Mon Sep 17 00:00:00 2001 From: Karthik Surabhi Date: Mon, 16 Sep 2024 10:11:08 -0500 Subject: [PATCH 2/5] updated-changes-remove-comments --- server/api/review-tags/index.get.ts | 13 +------------ server/utils/tasks/seed-cache.ts | 4 +--- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/server/api/review-tags/index.get.ts b/server/api/review-tags/index.get.ts index 4e167d34..a4c58f71 100644 --- a/server/api/review-tags/index.get.ts +++ b/server/api/review-tags/index.get.ts @@ -1,21 +1,10 @@ -// Import the defineEventHandler function from the 'h3' package -// This is used to create server-side event handlers -import { defineEventHandler } from 'h3'; -import { type ReviewTag } from '../../db/schema'; //import review tags from db schema - +import { type ReviewTag } from '../../db/schema'; import authenticateAdminRequest from '../../utils/admin'; -// Define and export the default event handler for this API endpoint export default defineEventHandler(async (event) => { - // Authenticate the request to ensure it's coming from an admin - // This function should throw an error if authentication fails - await authenticateAdminRequest(event); - //RetreiveTags from general memory storage and - //If no tags are found, default to an empty array const reviewTags = (await general_memoryStorage.getItem('reviewTags')) || []; - //Return the review tags as the response return reviewTags; }); diff --git a/server/utils/tasks/seed-cache.ts b/server/utils/tasks/seed-cache.ts index 8e58f816..6785b293 100644 --- a/server/utils/tasks/seed-cache.ts +++ b/server/utils/tasks/seed-cache.ts @@ -12,9 +12,7 @@ export async function seedCache() { .from(metaDataTable) .where(inArray(metaDataTable.key, ['seoConfig', 'careerSiteConfig', 'firstSetupAccessKey'])); - //getting the review tags from the reviewTagsTable const reviewTags = await db.select().from(reviewTagsTable); - console.log(reviewTags); //debug to check the reviewtags response // Do not save totalApplicants in cache const jobPostings = (await db.select().from(jobPostingsTable).orderBy(desc(jobPostingsTable.createdAt))).map((p) => ({ @@ -45,7 +43,7 @@ export async function seedCache() { general_memoryStorage.setItem('firstSetupAccessKey', firstSetupAccessKey), general_memoryStorage.setItem('remoteAssetBase', remoteAssetBase), general_memoryStorage.setItem('postings', jobPostings), - general_memoryStorage.setItem('reviewTags', reviewTags), //setting the reviewTags to general_memorystorage + general_memoryStorage.setItem('reviewTags', reviewTags), ]); return { result: true }; From b292ddeaddce1004f985ccd522c36029bca3a4fb Mon Sep 17 00:00:00 2001 From: Aman Desai <39585600+amandesai01@users.noreply.github.com> Date: Mon, 16 Sep 2024 20:49:58 +0530 Subject: [PATCH 3/5] Update server/utils/tasks/seed-cache.ts --- server/utils/tasks/seed-cache.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/utils/tasks/seed-cache.ts b/server/utils/tasks/seed-cache.ts index 6785b293..f397617f 100644 --- a/server/utils/tasks/seed-cache.ts +++ b/server/utils/tasks/seed-cache.ts @@ -1,5 +1,5 @@ import { desc, inArray } from 'drizzle-orm'; -import { jobPostingsTable, reviewTagsTable, metaDataTable } from '~~/server/db/schema'; //import the review tags table from schema +import { jobPostingsTable, reviewTagsTable, metaDataTable } from '~~/server/db/schema'; import type { CareerSiteConfig, SEOConfig } from '~~/shared/schemas/setting'; export async function seedCache() { From 01e35bbbe73e803198326831baf11621b524dfbd Mon Sep 17 00:00:00 2001 From: Aman Desai <39585600+amandesai01@users.noreply.github.com> Date: Mon, 16 Sep 2024 20:50:05 +0530 Subject: [PATCH 4/5] Update server/api/review-tags/index.get.ts --- server/api/review-tags/index.get.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/server/api/review-tags/index.get.ts b/server/api/review-tags/index.get.ts index a4c58f71..63696fd7 100644 --- a/server/api/review-tags/index.get.ts +++ b/server/api/review-tags/index.get.ts @@ -1,5 +1,4 @@ import { type ReviewTag } from '../../db/schema'; -import authenticateAdminRequest from '../../utils/admin'; export default defineEventHandler(async (event) => { await authenticateAdminRequest(event); From 4c1e085e63d2f71abf38f9bc85c44a781af2f729 Mon Sep 17 00:00:00 2001 From: Aman Desai <39585600+amandesai01@users.noreply.github.com> Date: Wed, 18 Sep 2024 11:58:38 +0530 Subject: [PATCH 5/5] Update index.get.ts --- server/api/review-tags/index.get.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/server/api/review-tags/index.get.ts b/server/api/review-tags/index.get.ts index 63696fd7..a4c58f71 100644 --- a/server/api/review-tags/index.get.ts +++ b/server/api/review-tags/index.get.ts @@ -1,4 +1,5 @@ import { type ReviewTag } from '../../db/schema'; +import authenticateAdminRequest from '../../utils/admin'; export default defineEventHandler(async (event) => { await authenticateAdminRequest(event);