Skip to content

Commit

Permalink
refactor(api): simplify schema export (#54722)
Browse files Browse the repository at this point in the history
  • Loading branch information
ojeytonwilliams committed May 10, 2024
1 parent ae1bc60 commit ab2f5a3
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 79 deletions.
2 changes: 1 addition & 1 deletion api/src/routes/certificate.ts
Expand Up @@ -2,7 +2,7 @@ import { type FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebo
import isEmail from 'validator/lib/isEmail';
import { find } from 'lodash';
import { CompletedChallenge } from '@prisma/client';
import { schemas } from '../schemas';
import * as schemas from '../schemas';
import { getChallenges } from '../utils/get-challenges';
import {
certIds,
Expand Down
2 changes: 1 addition & 1 deletion api/src/routes/challenge.ts
Expand Up @@ -5,7 +5,7 @@ import { CompletedExam, ExamResults } from '@prisma/client';
import isURL from 'validator/lib/isURL';

import { challengeTypes } from '../../../shared/config/challenge-types';
import { schemas } from '../schemas';
import * as schemas from '../schemas';
import {
jsCertProjectIds,
multifileCertProjectIds,
Expand Down
2 changes: 1 addition & 1 deletion api/src/routes/deprecated-endpoints.ts
@@ -1,6 +1,6 @@
import { type FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebox';

import { schemas } from '../schemas';
import * as schemas from '../schemas';

type Endpoints = [string, 'GET' | 'POST'][];

Expand Down
2 changes: 1 addition & 1 deletion api/src/routes/donate.ts
Expand Up @@ -5,7 +5,7 @@ import {
import Stripe from 'stripe';

import { donationSubscriptionConfig } from '../../../shared/config/donation-settings';
import { schemas } from '../schemas';
import * as schemas from '../schemas';
import { STRIPE_SECRET_KEY } from '../utils/env';

/**
Expand Down
2 changes: 1 addition & 1 deletion api/src/routes/email-subscription.ts
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { type FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebox';
import { schemas } from '../schemas';
import * as schemas from '../schemas';
import { getRedirectParams } from '../utils/redirection';

/**
Expand Down
2 changes: 1 addition & 1 deletion api/src/routes/settings.ts
Expand Up @@ -18,7 +18,7 @@ import { isProfane } from 'no-profanity';

import { blocklistedUsernames } from '../../../shared/config/constants';
import { isValidUsername } from '../../../shared/utils/validate';
import { schemas } from '../schemas';
import * as schemas from '../schemas';

type WaitMesssageArgs = {
sentAt: Date | null;
Expand Down
2 changes: 1 addition & 1 deletion api/src/routes/user.ts
@@ -1,7 +1,7 @@
import { type FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebox';
import { ObjectId } from 'mongodb';

import { schemas } from '../schemas';
import * as schemas from '../schemas';
// Loopback creates a 64 character string for the user id, this customizes
// nanoid to do the same. Any unique key _should_ be fine, though.
import { customNanoid } from '../utils/ids';
Expand Down
2 changes: 1 addition & 1 deletion api/src/schema.test.ts
@@ -1,7 +1,7 @@
import Ajv from 'ajv';
import secureSchema from 'ajv/lib/refs/json-schema-secure.json';

import { schemas } from './schemas';
import * as schemas from './schemas';

// it's not strict, but that's okay - we're not using it to validate data
const ajv = new Ajv({ strictTypes: false });
Expand Down
105 changes: 34 additions & 71 deletions api/src/schemas.ts
@@ -1,71 +1,34 @@
import { certSlug } from './schemas/certificate/cert-slug';
import { certificateVerify } from './schemas/certificate/certificate-verify';
import { backendChallengeCompleted } from './schemas/challenge/backend-challenge-completed';
import { coderoadChallengeCompleted } from './schemas/challenge/coderoad-challenge-completed';
import { exam } from './schemas/challenge/exam';
import { examChallengeCompleted } from './schemas/challenge/exam-challenge-completed';
import { modernChallengeCompleted } from './schemas/challenge/modern-challenge-completed';
import { msTrophyChallengeCompleted } from './schemas/challenge/ms-trophy-challenge-completed';
import { projectCompleted } from './schemas/challenge/project-completed';
import { saveChallenge } from './schemas/challenge/save-challenge';
import { deprecatedEndpoints } from './schemas/deprecated';
import { chargeStripeCard } from './schemas/donate/charge-stripe-card';
import { resubscribe } from './schemas/email-subscription/resubscribe';
import { unsubscribe } from './schemas/email-subscription/unsubscribe';
import { updateMyAbout } from './schemas/settings/update-my-about';
import { updateMyClassroomMode } from './schemas/settings/update-my-classroom-mode';
import { updateMyEmail } from './schemas/settings/update-my-email';
import { updateMyHonesty } from './schemas/settings/update-my-honesty';
import { updateMyKeyboardShortcuts } from './schemas/settings/update-my-keyboard-shortcuts';
import { updateMyPortfolio } from './schemas/settings/update-my-portfolio';
import { updateMyPrivacyTerms } from './schemas/settings/update-my-privacy-terms';
import { updateMyProfileUI } from './schemas/settings/update-my-profile-ui';
import { updateMyQuincyEmail } from './schemas/settings/update-my-quincy-email';
import { updateMySocials } from './schemas/settings/update-my-socials';
import { updateMyTheme } from './schemas/settings/update-my-theme';
import { updateMyUsername } from './schemas/settings/update-my-username';
import { deleteMsUsername } from './schemas/user/delete-ms-username';
import { deleteMyAccount } from './schemas/user/delete-my-account';
import { deleteUserToken } from './schemas/user/delete-user-token';
import { getSessionUser } from './schemas/user/get-session-user';
import { postMsUsername } from './schemas/user/post-ms-username';
import { reportUser } from './schemas/user/report-user';
import { resetMyProgress } from './schemas/user/reset-my-progress';
import { submitSurvey } from './schemas/user/submit-survey';

export const schemas = {
backendChallengeCompleted,
certificateVerify,
certSlug,
chargeStripeCard,
coderoadChallengeCompleted,
deleteMyAccount,
deleteMsUsername,
deleteUserToken,
deprecatedEndpoints,
exam,
examChallengeCompleted,
getSessionUser,
modernChallengeCompleted,
msTrophyChallengeCompleted,
postMsUsername,
projectCompleted,
saveChallenge,
submitSurvey,
reportUser,
resetMyProgress,
resubscribe,
unsubscribe,
updateMyAbout,
updateMyClassroomMode,
updateMyEmail,
updateMyHonesty,
updateMyKeyboardShortcuts,
updateMyPortfolio,
updateMyPrivacyTerms,
updateMyProfileUI,
updateMyQuincyEmail,
updateMySocials,
updateMyTheme,
updateMyUsername
};
export { certSlug } from './schemas/certificate/cert-slug';
export { certificateVerify } from './schemas/certificate/certificate-verify';
export { backendChallengeCompleted } from './schemas/challenge/backend-challenge-completed';
export { coderoadChallengeCompleted } from './schemas/challenge/coderoad-challenge-completed';
export { exam } from './schemas/challenge/exam';
export { examChallengeCompleted } from './schemas/challenge/exam-challenge-completed';
export { modernChallengeCompleted } from './schemas/challenge/modern-challenge-completed';
export { msTrophyChallengeCompleted } from './schemas/challenge/ms-trophy-challenge-completed';
export { projectCompleted } from './schemas/challenge/project-completed';
export { saveChallenge } from './schemas/challenge/save-challenge';
export { deprecatedEndpoints } from './schemas/deprecated';
export { chargeStripeCard } from './schemas/donate/charge-stripe-card';
export { resubscribe } from './schemas/email-subscription/resubscribe';
export { unsubscribe } from './schemas/email-subscription/unsubscribe';
export { updateMyAbout } from './schemas/settings/update-my-about';
export { updateMyClassroomMode } from './schemas/settings/update-my-classroom-mode';
export { updateMyEmail } from './schemas/settings/update-my-email';
export { updateMyHonesty } from './schemas/settings/update-my-honesty';
export { updateMyKeyboardShortcuts } from './schemas/settings/update-my-keyboard-shortcuts';
export { updateMyPortfolio } from './schemas/settings/update-my-portfolio';
export { updateMyPrivacyTerms } from './schemas/settings/update-my-privacy-terms';
export { updateMyProfileUI } from './schemas/settings/update-my-profile-ui';
export { updateMyQuincyEmail } from './schemas/settings/update-my-quincy-email';
export { updateMySocials } from './schemas/settings/update-my-socials';
export { updateMyTheme } from './schemas/settings/update-my-theme';
export { updateMyUsername } from './schemas/settings/update-my-username';
export { deleteMsUsername } from './schemas/user/delete-ms-username';
export { deleteMyAccount } from './schemas/user/delete-my-account';
export { deleteUserToken } from './schemas/user/delete-user-token';
export { getSessionUser } from './schemas/user/get-session-user';
export { postMsUsername } from './schemas/user/post-ms-username';
export { reportUser } from './schemas/user/report-user';
export { resetMyProgress } from './schemas/user/reset-my-progress';
export { submitSurvey } from './schemas/user/submit-survey';

0 comments on commit ab2f5a3

Please sign in to comment.