Skip to content

Commit

Permalink
fix: resolve signup form issues (#121)
Browse files Browse the repository at this point in the history
* Add log

* Add logs, change errors
  • Loading branch information
zivkovicmilos authored Sep 24, 2023
1 parent 1ac88b3 commit b2e9b19
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 25 deletions.
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.

0 comments on commit b2e9b19

Please sign in to comment.