Skip to content

Commit

Permalink
feat: org schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
johnshift committed May 14, 2024
1 parent d38f9e5 commit 70b5db6
Show file tree
Hide file tree
Showing 2 changed files with 163 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/orgs/core/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
export const ORG_REVIEW_LOCATIONS = ['ONSITE', 'REMOTE', 'HYBRID'] as const;

export const ORG_REVIEW_TIMEZONES = [
'ASYNC',
'GMT-12',
'GMT-11',
'GMT-10',
'GMT-09',
'GMT-08',
'GMT-07',
'GMT-06',
'GMT-05',
'GMT-04',
'GMT-03',
'GMT-02',
'GMT-01',
'GMT',
'GMT+01',
'GMT+02',
'GMT+03',
'GMT+04',
'GMT+05',
'GMT+06',
'GMT+07',
'GMT+08',
'GMT+09',
'GMT+10',
'GMT+11',
'GMT+12',
'GMT+13',
'GMT+14',
] as const;

export const ORG_TEST_IDS = {
ORG_CARD: 'org-card',
} as const;

export const ORG_RATING_LABELS = {
benefits: 'Benefits' as const,
careerGrowth: 'Career Growth' as const,
diversityInclusion: 'Diversity & Inclusion' as const,
management: 'Management' as const,
product: 'Overall Product' as const,
compensation: 'Compensation' as const,
onboarding: 'Onboarding' as const,
workLifeBalance: 'Work Life Balance' as const,
};
116 changes: 116 additions & 0 deletions src/orgs/core/schemas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import { z } from 'zod';

import {
fundingRoundSchema,
investorSchema,
jobInfoSchema,
jobInfoTagsSchema,
orgInfoSchema,
projectAllInfoSchema,
} from '@/shared/core/schemas';

import { ORG_REVIEW_LOCATIONS, ORG_REVIEW_TIMEZONES } from './constants';

export const orgListItemSchema = orgInfoSchema
.pick({
orgId: true,
name: true,
location: true,
headcountEstimate: true,
logoUrl: true,
aggregateRating: true,
reviewCount: true,
})
.merge(
z.object({
url: z.string(),
jobCount: z.number(),
projectCount: z.number(),
lastFundingDate: z.number(),
lastFundingAmount: z.number(),
community: z.array(z.string()),
}),
);
export type OrgListItem = z.infer<typeof orgListItemSchema>;

export const orgJobSchema = jobInfoSchema
.pick({
id: true,
title: true,
shortUUID: true,
summary: true,
})
.merge(jobInfoTagsSchema);
export type OrgJob = z.infer<typeof orgJobSchema>;

const starRatingSchema = z.number().min(0).max(5).nullable();
export type StarRating = z.infer<typeof starRatingSchema>;

export const orgRatingSchema = z.object({
benefits: starRatingSchema,
careerGrowth: starRatingSchema,
diversityInclusion: starRatingSchema,
management: starRatingSchema,
product: starRatingSchema,
compensation: starRatingSchema,
onboarding: starRatingSchema,
workLifeBalance: starRatingSchema,
});
export type OrgRating = z.infer<typeof orgRatingSchema>;

export const orgCompensationSchema = z.object({
offersTokenAllocation: z.boolean(),
salary: z.number().nullable(),
currency: z.string().nullable(),
});
export type OrgCompensation = z.infer<typeof orgCompensationSchema>;

export const orgReviewLocationSchema = z.enum(ORG_REVIEW_LOCATIONS);
export type OrgReviewLocation = z.infer<typeof orgReviewLocationSchema>;

export const orgReviewTimezoneSchema = z.enum(ORG_REVIEW_TIMEZONES);
export type OrgReviewTimezone = z.infer<typeof orgReviewTimezoneSchema>;

export const orgStaffReviewSchema = z.object({
id: z.string().min(1).nullable(),
title: z.string().nullable(),
location: orgReviewLocationSchema.nullable(),
timezone: orgReviewTimezoneSchema.nullable(),
pros: z.string().min(1).max(500).nullable(),
cons: z.string().min(1).max(500).nullable(),
});
export type OrgStaffReview = z.infer<typeof orgStaffReviewSchema>;

export const orgReviewSchema = z.object({
membershipStatus: z.string().min(1).nullable(),
startDate: z.number().nullable(),
endDate: z.number().nullable(),
reviewedTimestamp: z.number().nullable(),
commitCount: z.number().nullable(),
compensation: orgCompensationSchema,
rating: orgRatingSchema,
review: orgStaffReviewSchema,
});
export type OrgReview = z.infer<typeof orgReviewSchema>;

export const orgDetailsSchema = z
.object({
projects: z.array(projectAllInfoSchema),
fundingRounds: z.array(fundingRoundSchema),
investors: z.array(investorSchema),
jobs: z.array(orgJobSchema),
aggregateRating: starRatingSchema,
aggregateRatings: orgRatingSchema,
reviewCount: z.number(),
reviews: z.array(orgReviewSchema.omit({ compensation: true })),
})
.merge(orgInfoSchema);
export type OrgDetails = z.infer<typeof orgDetailsSchema>;

export const orgListQueryPageSchema = z.object({
page: z.number(),
count: z.number(),
total: z.number(),
data: z.array(orgListItemSchema),
});
export type OrgListQueryPage = z.infer<typeof orgListQueryPageSchema>;

0 comments on commit 70b5db6

Please sign in to comment.