From e4d15127578b2292260b2bf78ed70630f655bdb7 Mon Sep 17 00:00:00 2001
From: karthik8239 <43171496+karthik8239@users.noreply.github.com>
Date: Tue, 1 Oct 2024 07:54:26 -0400
Subject: [PATCH] feat(career-page): show total postings (#172)
---
app/components/Ui/Tag.vue | 5 +++++
app/composables/state.ts | 4 ++++
app/pages/admin/applications.vue | 4 +---
app/pages/index.vue | 7 +++++--
app/plugins/setup-state.ts | 12 +++++++-----
server/api/public/config.get.ts | 3 ++-
server/utils/tasks/seed-cache.ts | 11 ++++++++++-
7 files changed, 34 insertions(+), 12 deletions(-)
create mode 100644 app/components/Ui/Tag.vue
diff --git a/app/components/Ui/Tag.vue b/app/components/Ui/Tag.vue
new file mode 100644
index 00000000..f64a2e29
--- /dev/null
+++ b/app/components/Ui/Tag.vue
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/app/composables/state.ts b/app/composables/state.ts
index 79733635..d9af970b 100644
--- a/app/composables/state.ts
+++ b/app/composables/state.ts
@@ -13,6 +13,10 @@ export function useOnboardingStatusState() {
return useState('onboarding-status', () => false);
}
+export function useTotalActivePostingsState() {
+ return useState('total-active-postings', () => 0);
+}
+
export function useCareerSiteConfigObjectState() {
return useObjectState('career-site-config');
}
diff --git a/app/pages/admin/applications.vue b/app/pages/admin/applications.vue
index be42c2bb..1acceb0f 100644
--- a/app/pages/admin/applications.vue
+++ b/app/pages/admin/applications.vue
@@ -58,9 +58,7 @@ watchEffect(() => {
{{ postingsById[posting] || '' }}
-
- {{ applications[posting]?.length }} Applicants
-
+ {{ applications[posting]?.length }} Applicants
- Open Positions
+
+ Open Positions
+ {{ totalActivePostings }}
+
diff --git a/app/plugins/setup-state.ts b/app/plugins/setup-state.ts
index da2321be..bb2d267f 100644
--- a/app/plugins/setup-state.ts
+++ b/app/plugins/setup-state.ts
@@ -3,18 +3,20 @@ export default defineNuxtPlugin(async () => {
const onboardingStatus = useOnboardingStatusState();
const careerSiteConfigObjectState = useCareerSiteConfigObjectState();
const seoConfigObjectState = useSeoConfigObjectState();
+ const totalActivePostings = useTotalActivePostingsState();
try {
const publicConfigRequest = await useFetch('/api/public/config');
if (!publicConfigRequest.data.value) {
throw new Error('config not received in response ' + publicConfigRequest.data.value);
}
- const pubicConfig = publicConfigRequest.data.value;
+ const publicConfig = publicConfigRequest.data.value;
- remoteAssetBase.value = pubicConfig.remoteAssetBase;
- onboardingStatus.value = pubicConfig.onboardingStatus;
- careerSiteConfigObjectState.setData(pubicConfig.settings.careerSite);
- seoConfigObjectState.setData(pubicConfig.settings.seo);
+ remoteAssetBase.value = publicConfig.remoteAssetBase;
+ onboardingStatus.value = publicConfig.onboardingStatus;
+ totalActivePostings.value = publicConfig.totalActivePostings;
+ careerSiteConfigObjectState.setData(publicConfig.settings.careerSite);
+ seoConfigObjectState.setData(publicConfig.settings.seo);
} catch (error) {
console.error('error fetching remote-asset-config', error);
}
diff --git a/server/api/public/config.get.ts b/server/api/public/config.get.ts
index 05eaaa79..3a46d467 100644
--- a/server/api/public/config.get.ts
+++ b/server/api/public/config.get.ts
@@ -4,6 +4,7 @@ import type { CareerSiteConfig, SEOConfig } from '~~/shared/schemas/setting';
export default defineEventHandler(async () => {
const remoteAssetBase = (await general_memoryStorage.getItem('remoteAssetBase')) as string;
const onboardingStatus = !((await general_memoryStorage.getItem('firstSetupAccessKey')) as string);
+ const totalActivePostings = (await general_memoryStorage.getItem('totalActivePostings')) as number;
const settings = {
careerSite: {},
@@ -13,5 +14,5 @@ export default defineEventHandler(async () => {
settings.seo = (await settings_memoryStorage.getItem('seoConfig')) as SEOConfig;
settings.careerSite = (await settings_memoryStorage.getItem('careerSiteConfig')) as CareerSiteConfig;
- return { remoteAssetBase, onboardingStatus, settings };
+ return { remoteAssetBase, onboardingStatus, totalActivePostings, settings };
});
diff --git a/server/utils/tasks/seed-cache.ts b/server/utils/tasks/seed-cache.ts
index f397617f..da645e23 100644
--- a/server/utils/tasks/seed-cache.ts
+++ b/server/utils/tasks/seed-cache.ts
@@ -1,4 +1,4 @@
-import { desc, inArray } from 'drizzle-orm';
+import { desc, inArray, eq, count } from 'drizzle-orm';
import { jobPostingsTable, reviewTagsTable, metaDataTable } from '~~/server/db/schema';
import type { CareerSiteConfig, SEOConfig } from '~~/shared/schemas/setting';
@@ -20,6 +20,14 @@ export async function seedCache() {
totalApplicants: -1,
}));
+ const totalActivePostings =
+ (
+ await db
+ .select({ count: count(jobPostingsTable.id) })
+ .from(jobPostingsTable)
+ .where(eq(jobPostingsTable.isPublished, true))
+ )[0]?.count || 0;
+
const settings = {
careerSite: {},
seo: {},
@@ -44,6 +52,7 @@ export async function seedCache() {
general_memoryStorage.setItem('remoteAssetBase', remoteAssetBase),
general_memoryStorage.setItem('postings', jobPostings),
general_memoryStorage.setItem('reviewTags', reviewTags),
+ general_memoryStorage.setItem('totalActivePostings', totalActivePostings),
]);
return { result: true };