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

fix: resolve signup form issues #121

Merged
merged 2 commits into from
Sep 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 0 additions & 11 deletions signup/functions/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,19 @@ export enum ApplicationEnv {
}

const {
NODE_PORT,
NODE_HOST,
NODE_ENV,
REDIS_URL,
MAILCHIMP_API_KEY,
MAILCHIMP_API_SERVER,
MAILCHIMP_AUDIENCE_ID,
MAILCHIMP_JOURNEY_ID,
MAILCHIMP_JOURNEY_STEP,
TOKEN_LIST
} = process.env;

const ENV: ApplicationEnv =
(NODE_ENV as ApplicationEnv) || ApplicationEnv.DEVELOPMENT;

export const CONFIG = {
REDIS_URL,
MAILCHIMP_API_KEY,
MAILCHIMP_API_SERVER,
MAILCHIMP_AUDIENCE_ID,
MAILCHIMP_JOURNEY_ID,
MAILCHIMP_JOURNEY_STEP,
TOKEN_LIST,
NODE_PORT,
NODE_HOST,
NODE_ENV: ENV
};
20 changes: 17 additions & 3 deletions signup/functions/subscribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,22 @@ import mailchimp from '@mailchimp/mailchimp_marketing';
import type { Handler, HandlerEvent } from '@netlify/functions';

import { CONFIG } from './config';
import { SubscribeRequest } from './types';
import subscribeUserSchema from './schemas/users.schema';
import { RedisClient } from './services/redis';
import getRandomToken from './helpers/token.helper';

interface SubscribeRequest {
firstName: string;
lastName: string;
email: string;
githubHandle: string;
socialHandle: string;
interests: string;
receiveNews: boolean;
participate: boolean;
termsAndConditions: boolean;
}

const ajv = new Ajv();
ajvFormats(ajv);

Expand All @@ -26,22 +37,25 @@ export async function handler(event: HandlerEvent): Handler {
// Validate the request
const subscribeRequest: SubscribeRequest = JSON.parse(event.body);

// Intentional; TODO Remove
console.log(subscribeRequest);

const isValid: boolean = ajv.validate(
subscribeUserSchema,
subscribeRequest
);
if (!isValid) {
return {
statusCode: 400,
body: JSON.stringify({ errors: 'Bad request' })
body: JSON.stringify({ errors: 'Unable to validate request' })
};
}

// Make sure the ToC is accepted if the game is played
if (subscribeRequest.termsAndConditions !== subscribeRequest.participate) {
return {
statusCode: 400,
body: JSON.stringify({ errors: { message: 'Bad request' } })
body: JSON.stringify({ errors: { message: 'Request is invalid' } })
};
}

Expand Down
11 changes: 0 additions & 11 deletions signup/functions/types.ts

This file was deleted.