From 7572f99f7438fc0980b957cc8846b5ecf22dfdd7 Mon Sep 17 00:00:00 2001 From: Oliver Eyton-Williams Date: Tue, 2 May 2023 18:54:05 +0200 Subject: [PATCH] refactor(api): remove unused endpoints (#50252) Also adds "dev" as an alias because I keep trying to use it. --- api/package.json | 1 + api/src/app.ts | 2 - api/src/routes/validation-test.ts | 61 ------------------------------- 3 files changed, 1 insertion(+), 63 deletions(-) delete mode 100644 api/src/routes/validation-test.ts diff --git a/api/package.json b/api/package.json index 235f7a4ff51..0316131b858 100644 --- a/api/package.json +++ b/api/package.json @@ -53,6 +53,7 @@ "scripts": { "build": "tsc -p tsconfig.build.json", "clean": "rm -rf dist", + "dev": "pnpm develop", "develop": "nodemon src/server.ts", "start": "FREECODECAMP_NODE_ENV=production node dist/server.js", "test": "jest --force-exit", diff --git a/api/src/app.ts b/api/src/app.ts index 697456ec73e..0b94fce4357 100644 --- a/api/src/app.ts +++ b/api/src/app.ts @@ -23,7 +23,6 @@ import sessionAuth from './plugins/session-auth'; import { testRoutes } from './routes/test'; import { settingRoutes } from './routes/settings'; import { auth0Routes, devLoginCallback } from './routes/auth'; -import { testValidatedRoutes } from './routes/validation-test'; import { testMiddleware } from './middleware'; import prismaPlugin from './db/prisma'; @@ -124,7 +123,6 @@ export const build = async ( void fastify.register(devLoginCallback, { prefix: '/auth' }); } void fastify.register(settingRoutes); - void fastify.register(testValidatedRoutes); return fastify; }; diff --git a/api/src/routes/validation-test.ts b/api/src/routes/validation-test.ts deleted file mode 100644 index 545d70a80e0..00000000000 --- a/api/src/routes/validation-test.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { Type } from '@fastify/type-provider-typebox'; - -import type { FastifyInstanceWithTypeProvider } from '../app'; -import { responseSchema, subSchema } from '../schemas/example'; - -export const testValidatedRoutes = ( - fastify: FastifyInstanceWithTypeProvider, - _options: never, - done: (err?: Error) => void -): void => { - fastify.get( - '/route-with-validation', - { - schema: { - querystring: Type.Object({ - foo: Type.Number(), - bar: Type.String() - }) - } - }, - request => { - const { foo, bar } = request.query; - - // Eslint can use the types given by TypeBoxTypeProvider: - // eslint-disable-next-line @typescript-eslint/restrict-plus-operands - const fooBar = foo + bar; - return { foo, bar, fooBar }; - } - ); - - fastify.post( - '/route-with-validation-shared-schema', - { - schema: { - body: Type.Object({ - foo: Type.Number(), - bar: Type.String(), - sub: subSchema - }), - response: { - 200: responseSchema - } - } - }, - request => { - const { foo, bar } = request.body; - // The TypeProvider constrains this by requiring value: string and - // otherValue: boolean. Anything else is a type error. 'ignored' is - // neither type checked nor returned, so it's safe. 'optional' is - // self-explanatory. - return { - value: bar, - otherValue: !foo, - ignored: 'not in reply', - ...(foo == 2 && { optional: 'optional' }) - }; - } - ); - - done(); -};