Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

seed-cache-review-tags-api #159

Merged
merged 5 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions server/api/review-tags/index.get.ts
Original file line number Diff line number Diff line change
@@ -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';
amandesai01 marked this conversation as resolved.
Show resolved Hide resolved
amandesai01 marked this conversation as resolved.
Show resolved Hide resolved

// 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<ReviewTag[]>('reviewTags')) || [];

//Return the review tags as the response
return reviewTags;
});
7 changes: 6 additions & 1 deletion server/utils/tasks/seed-cache.ts
Original file line number Diff line number Diff line change
@@ -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
amandesai01 marked this conversation as resolved.
Show resolved Hide resolved
import type { CareerSiteConfig, SEOConfig } from '~~/shared/schemas/setting';

export async function seedCache() {
Expand All @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amandesai01 you mean the comments or code?

Copy link
Contributor Author

@karthik8239 karthik8239 Sep 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed the comments and logging


// Do not save totalApplicants in cache
const jobPostings = (await db.select().from(jobPostingsTable).orderBy(desc(jobPostingsTable.createdAt))).map((p) => ({
...p,
Expand Down Expand Up @@ -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 };
Expand Down