From 73459899179b6659407904cf09c3f0f999b4c4e7 Mon Sep 17 00:00:00 2001 From: Oliver Eyton-Williams Date: Mon, 19 Aug 2024 13:30:02 +0200 Subject: [PATCH] refactor(api): import add-donation schema (#55876) --- api/src/routes/donate.ts | 22 ++-------------------- api/src/schemas.ts | 1 + api/src/schemas/donate/add-donation.ts | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 20 deletions(-) create mode 100644 api/src/schemas/donate/add-donation.ts diff --git a/api/src/routes/donate.ts b/api/src/routes/donate.ts index 1111ad85cb0..4607f6aacb6 100644 --- a/api/src/routes/donate.ts +++ b/api/src/routes/donate.ts @@ -1,7 +1,4 @@ -import { - Type, - type FastifyPluginCallbackTypebox -} from '@fastify/type-provider-typebox'; +import { type FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebox'; import Stripe from 'stripe'; import { donationSubscriptionConfig, @@ -62,22 +59,7 @@ export const donateRoutes: FastifyPluginCallbackTypebox = ( fastify.post( '/donate/add-donation', { - schema: { - body: Type.Object({}), - response: { - 200: Type.Object({ - isDonating: Type.Boolean() - }), - 400: Type.Object({ - message: Type.Literal('User is already donating.'), - type: Type.Literal('info') - }), - 500: Type.Object({ - message: Type.Literal('Something went wrong.'), - type: Type.Literal('danger') - }) - } - } + schema: schemas.addDonation }, async (req, reply) => { try { diff --git a/api/src/schemas.ts b/api/src/schemas.ts index c841ca03bf0..28849f28537 100644 --- a/api/src/schemas.ts +++ b/api/src/schemas.ts @@ -11,6 +11,7 @@ export { msTrophyChallengeCompleted } from './schemas/challenge/ms-trophy-challe export { projectCompleted } from './schemas/challenge/project-completed'; export { saveChallenge } from './schemas/challenge/save-challenge'; export { deprecatedEndpoints } from './schemas/deprecated'; +export { addDonation } from './schemas/donate/add-donation'; export { chargeStripeCard } from './schemas/donate/charge-stripe-card'; export { chargeStripe } from './schemas/donate/charge-stripe'; export { createStripePaymentIntent } from './schemas/donate/create-stripe-payment-intent'; diff --git a/api/src/schemas/donate/add-donation.ts b/api/src/schemas/donate/add-donation.ts new file mode 100644 index 00000000000..6d0f7f0d3a2 --- /dev/null +++ b/api/src/schemas/donate/add-donation.ts @@ -0,0 +1,18 @@ +import { Type } from '@fastify/type-provider-typebox'; + +export const addDonation = { + body: Type.Object({}), + response: { + 200: Type.Object({ + isDonating: Type.Boolean() + }), + 400: Type.Object({ + message: Type.Literal('User is already donating.'), + type: Type.Literal('info') + }), + 500: Type.Object({ + message: Type.Literal('Something went wrong.'), + type: Type.Literal('danger') + }) + } +};