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

total-positions-addition-public-config-api-UI #172

Merged
merged 8 commits into from
Oct 1, 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
4 changes: 4 additions & 0 deletions app/composables/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export function useOnboardingStatusState() {
return useState<boolean>('onboarding-status', () => false);
}

export function usePositionState() {
return useState<number>('totalPositions', () => 0);
}

export function useCareerSiteConfigObjectState() {
return useObjectState<CareerSiteConfig>('career-site-config');
}
Expand Down
3 changes: 2 additions & 1 deletion app/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const { data: postings } = await usePublicPostingsRepository();
const { data: careerSiteConfig } = useCareerSiteConfigObjectState();
const { data: seoConfig } = useSeoConfigObjectState();

const totalPositions = usePositionState();
const publicConfig = useRuntimeConfig().public;

let title: string = 'Careers'; // TODO: need better defaults (this will hardly be the case);
Expand Down Expand Up @@ -42,6 +42,7 @@ useSeoMeta({
<main class="grow w-full lg:w-2/3 mx-auto mt-20 p-2">
<SiteHeader />
<h3 class="text-lg leading-snug text-zinc-600 font-bold mt-8 mb-2">Open Positions</h3>
<span class="text-sm text-zinc-500">({{ totalPositions }})</span>
karthik8239 marked this conversation as resolved.
Show resolved Hide resolved
karthik8239 marked this conversation as resolved.
Show resolved Hide resolved
<div class="space-y-2" v-if="postings">
<PostingCard v-for="posting in postings" :key="posting.id" :posting="posting" />
</div>
Expand Down
2 changes: 2 additions & 0 deletions app/plugins/setup-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export default defineNuxtPlugin(async () => {
const onboardingStatus = useOnboardingStatusState();
const careerSiteConfigObjectState = useCareerSiteConfigObjectState();
const seoConfigObjectState = useSeoConfigObjectState();
const totalPositionsState = usePositionState();

try {
const publicConfigRequest = await useFetch('/api/public/config');
Expand All @@ -13,6 +14,7 @@ export default defineNuxtPlugin(async () => {

remoteAssetBase.value = pubicConfig.remoteAssetBase;
onboardingStatus.value = pubicConfig.onboardingStatus;
totalPositionsState.value = pubicConfig.totalPositions;
careerSiteConfigObjectState.setData(pubicConfig.settings.careerSite);
seoConfigObjectState.setData(pubicConfig.settings.seo);
} catch (error) {
Expand Down
3 changes: 2 additions & 1 deletion server/api/public/config.get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 totalPositions = (await general_memoryStorage.getItem('totalPositions')) as number;

const settings = {
careerSite: {},
Expand All @@ -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, totalPositions, settings };
});
10 changes: 9 additions & 1 deletion server/utils/tasks/seed-cache.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { desc, inArray } from 'drizzle-orm';
import { desc, inArray, eq } from 'drizzle-orm';
import { jobPostingsTable, reviewTagsTable, metaDataTable } from '~~/server/db/schema';
import type { CareerSiteConfig, SEOConfig } from '~~/shared/schemas/setting';

Expand All @@ -20,6 +20,13 @@ export async function seedCache() {
totalApplicants: -1,
}));

const activePostings = await db
.select({ totalApplicants: jobPostingsTable.totalApplicants })
.from(jobPostingsTable)
.where(eq(jobPostingsTable.isPublished, true));

const totalActivePostings = activePostings.length;
Copy link
Member

Choose a reason for hiding this comment

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

you need to run count query to get count.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So the goal is to get total applicants ? not active postings?

Copy link
Member

Choose a reason for hiding this comment

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

you have to show posting count, not applicants count. Reason we need that from database is because we have future plans in cache management and paging side, so frontend won't be able to show length directly.


const settings = {
careerSite: {},
seo: {},
Expand All @@ -44,6 +51,7 @@ export async function seedCache() {
general_memoryStorage.setItem('remoteAssetBase', remoteAssetBase),
general_memoryStorage.setItem('postings', jobPostings),
general_memoryStorage.setItem('reviewTags', reviewTags),
general_memoryStorage.setItem('totalPositions', totalActivePostings),
]);

return { result: true };
Expand Down