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

feat: API endpoint to create event check-in link #115

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
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
15 changes: 14 additions & 1 deletion functions/src/application/portal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Response, Request } from "express";
import { Response, Request, response } from "express";
import * as Sentry from "@sentry/node";
import { firestore } from "../admin/admin";
import { send_dynamic_template, upsert_contact } from "../mail/sendgrid";
Expand All @@ -7,6 +7,7 @@ import logger from "../services/logging";
import { environment } from "../environment";
import { build_vanity_link_v2, VanityReqBody } from "../custom/vanity";
import { BadRequestError } from "../utilities/errors/BadRequestError";
import { ACMEvent, create_event_v2 } from "../custom/event";

const profile_collection = environment.FIRESTORE_PROFILE_COLLECTION as string;
const event_collection = environment.FIRESTORE_EVENT_COLLECTION as string;
Expand Down Expand Up @@ -328,3 +329,15 @@ export const create_vanity_link = async (req: Request<{}, {}, VanityReqBody>, re
return res.status(400).json(errObj.serialize());
}
};

export const create_event_checkin_link = async (req: Request<{}, {}, ACMEvent, {}>, res: Response) => {
try {
const response_data = await create_event_v2(req.body);
return res.json(response_data);
} catch (error) {
return res.status(500).json({
msg: "Server Error",
error,
});
}
};
80 changes: 80 additions & 0 deletions functions/src/custom/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ export interface EventDoc {
public: boolean;
}

export interface ACMEvent extends EventDoc {
first_name: string;
last_name: string;
email: string;
}

const event_collection = environment.FIRESTORE_EVENT_COLLECTION as string;

export const create_event = async (document: FirebaseFirestore.DocumentData): Promise<void> => {
Expand Down Expand Up @@ -96,3 +102,77 @@ const create_map = async (document: EventDoc): Promise<void> => {
message: "Successfully created an event check-in",
});
};

export const create_event_v2 = async ({
first_name,
last_name,
email,
name,
path_name,
date,
public: public_event,
}: ACMEvent) => {
try {
const email_options: sendgrid_email = {
from: "[email protected]",
from_name: "ACM Development",
template_id: `${environment.SENDGRID_EVENT_TEMPLATE_ID}`,
to: email,
dynamicSubstitutions: {
first_name,
last_name,
name,
checkin_link: `${environment.URL_PROD}/checkin/${path_name}`,
date,
preheader: "Successful Event Check-in Creation Connection",
subject: "Event Creation Confirmation",
public_event,
},
};

const data: EventDoc = {
name,
path_name,
date,
public: public_event,
};

const message: slack_message = {
form_name: "Event Check-in Generator",
name: `${first_name} ${last_name}`,
email,
url: `${environment.URL_PROD}/checkin/${path_name}`,
};

await saveToDB(data);
await send_dynamic_template(email_options);
await log_to_slack(message);

return {
msg: "Successful Event Check-in Creation Connection",
checkin_link: `${environment.URL_PROD}/checkin/${path_name}`,
};
} catch (err) {
logger.log(err);
Sentry.captureException(err);
return err;
}
};

const saveToDB = async (data: EventDoc) => {
// TODO: Add logic to save stuff into MongoDB
};

const create_map = async (document: EventDoc): Promise<void> => {
await firestore
.collection(event_collection)
.doc(document.path_name)
.create({
...document,
path_name: `/checkin/${document.path_name}`,
});
logger.log({
...document,
message: "Successfully created an event check-in",
});
};
1 change: 1 addition & 0 deletions functions/src/routes/express_portal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ app_portal.post("/auth0/verify-discord", verify_in_acm_server);

// Create Vanity Link
app_portal.post("/gsuite/vanity/create", portalFunctions.create_vanity_link);
app_portal.post("/gsuite/event/checkin/create", portalFunctions.create_event_checkin_link);

// http server endpoints
export default app_portal;