Skip to content

Commit

Permalink
Merge pull request #13 from YouthCatalyst/TECH-177
Browse files Browse the repository at this point in the history
TECH-177: Activate Mentors in FlashCampus when Onboarding Complete in…
  • Loading branch information
daniyusra authored Sep 1, 2024
2 parents bf2e1c4 + 8ea65d4 commit c3ca0bb
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
8 changes: 7 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,15 @@ NEXTAUTH_COOKIE_DOMAIN=
# Set this to '1' if you don't want Cal to collect anonymous usage
CALCOM_TELEMETRY_DISABLED=

# FC Registration Token
# Account Registration Token (invoked by Drive)
USER_CREATION_ACCESS_KEY=

# For Accessing FlashCampus Token (issued by FlashCampus / used by Cal.com to Encode)
FLASHCAMPUS_KEY=

# Link for targeted Flash Campus
FLASHCAMPUS_LINK=

# ApiKey for cronjobs
CRON_API_KEY='0cc0e6c35519bba620c9360cfe3e68d0'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Prisma } from "@prisma/client";
import axios from "axios";
import jwt from "jsonwebtoken";
// eslint-disable-next-line no-restricted-imports
import { keyBy } from "lodash";
import type { GetServerSidePropsContext, NextApiResponse } from "next";
Expand Down Expand Up @@ -370,6 +372,9 @@ export const updateProfileHandler = async ({ ctx, input }: UpdateProfileOptions)
}
}

//notify FlashCampus regarding update/activation
activateUserInFlashCampus({ ctx, input });

return {
...input,
email: emailVerification && !secondaryEmail?.emailVerified ? user.email : input.email,
Expand Down Expand Up @@ -399,3 +404,38 @@ const handleUserMetadata = ({ ctx, input }: UpdateProfileOptions) => {
// Required so we don't override and delete saved values
return { ...userMetadata, ...cleanMetadata };
};

async function activateUserInFlashCampus({ ctx, input }: UpdateProfileOptions) {
const { user } = ctx;

if (user.username != null) {
const email = user.email;

const defaultLink = `${process.env.NEXT_PUBLIC_WEBAPP_URL}/${user.username}/15min_meeting`;

const url = `${process.env.FLASHCAMPUS_LINK}/api/account/activate-mentor`;

const tokenizedPayload = jwt.sign(
{
email,
default_link: defaultLink,
},
process.env.FLASHCAMPUS_KEY as string,
{
expiresIn: 1800, // 30 min
}
);

const result = await axios.post(
url,
{ payload: tokenizedPayload },
{
headers: {
"Content-Type": "application/x-www-form-urlencoded;charset=utf-8",
},
}
);

//todo: if the results are a failure (e.g on a server failure case), they should be logged. Or something.
}
}
2 changes: 2 additions & 0 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@
"EMAIL_SERVER_USER",
"EMAIL_SERVER",
"EXCHANGE_DEFAULT_EWS_URL",
"FLASHCAMPUS_KEY",
"FLASHCAMPUS_LINK",
"FORMBRICKS_FEEDBACK_SURVEY_ID",
"AVATARAPI_USERNAME",
"AVATARAPI_PASSWORD",
Expand Down

0 comments on commit c3ca0bb

Please sign in to comment.