Skip to content

Commit

Permalink
Added the ability to check whether the provided meetup groups actuall…
Browse files Browse the repository at this point in the history
…y exist.
  • Loading branch information
Matthew Monahan committed Dec 17, 2019
1 parent a15e71b commit b078d72
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@nestjs/core": "^6.7.2",
"@nestjs/platform-express": "^6.7.2",
"@types/ical": "^0.6.1",
"axios": "^0.19.0",
"ical": "^0.6.0",
"ical-generator": "^1.9.2",
"reflect-metadata": "^0.1.13",
Expand Down
12 changes: 9 additions & 3 deletions src/controllers/calendar.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import {
import { Response } from "express";

import { CalendarService } from "../services";

const getMeetupICalUrl = (groupName: string): string =>
`https://www.meetup.com/${groupName}/events/ical/`;
import { getMeetupICalUrl, checkMeetupGroupExists } from "../utils";

@Controller()
export class CalendarController {
Expand All @@ -29,6 +27,14 @@ export class CalendarController {

// Parse the meetup groups, some validation about whether or not they exist would be nice...
const groups = meetupGroups.split(",");
const result = await Promise.all(
groups.map(group => checkMeetupGroupExists(group)),
);
if (result.indexOf(false) > -1) {
throw new BadRequestException(
"One or more meetup groups were not found",
);
}

console.log(`Getting events for: `, groups);

Expand Down
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./meetup.utils";
15 changes: 15 additions & 0 deletions src/utils/meetup.utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Axios from "axios";

export const getMeetupICalUrl = (groupName: string): string =>
`https://www.meetup.com/${groupName}/events/ical/`;

export const checkMeetupGroupExists = async (
groupName: string,
): Promise<boolean> => {
try {
await Axios.head(getMeetupICalUrl(groupName), { maxRedirects: 0 });
return true;
} catch (error) {
return false;
}
};
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ aws4@^1.8.0:
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.9.0.tgz#24390e6ad61386b0a747265754d2a17219de862c"
integrity sha512-Uvq6hVe90D0B2WEnUqtdgY1bATGz3mw33nH9Y+dmA+w5DHvUmBgkr5rM/KCHpCsiFNRUfokW/szpPPgMK2hm4A==

[email protected]:
[email protected], axios@^0.19.0:
version "0.19.0"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.0.tgz#8e09bff3d9122e133f7b8101c8fbdd00ed3d2ab8"
integrity sha512-1uvKqKQta3KBxIz14F2v06AEHZ/dIoeKfbTRkK1E5oqjDnuEerLmYTgJB5AiQZHJcljpg1TuRzdjDR06qNk0DQ==
Expand Down

0 comments on commit b078d72

Please sign in to comment.