Skip to content

Commit

Permalink
Reactivate college (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
burale authored Feb 13, 2024
1 parent 935eb67 commit 06de710
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/functions/invite-college.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ app.http("invite-college", {
let activeCollegeGroups = (await getAllCollegeGroups()).filter(
(collegeGroup) =>
collegeGroup.embeddedData?.groupStatus == "NeedsInvite"
&& !collegeGroup.embeddedData?.unsubscribed
&& !collegeGroup?.unsubscribed
);

for (let x = 0; x < activeCollegeGroups.length; x++) {
Expand Down
43 changes: 43 additions & 0 deletions src/functions/re-activate-college.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import "dotenv/config";
import config from "../config";
import { getAllCollegeGroups } from "../qualtrics/college-group-service";
import { app } from "@azure/functions";
import axios from "axios";
const urls = require("./urls");

app.http("re-activate-college", {
methods: ["GET", "POST"],
authLevel: "function",
handler: async (request, context) => {
const timeElapsed = Date.now();
const currentDate = new Date(timeElapsed);

let activeCollegeGroups = (await getAllCollegeGroups()).filter(
(collegeGroup) =>
collegeGroup.embeddedData?.groupStatus == "Active"
&& collegeGroup?.unsubscribed
);

for (let x = 0; x < activeCollegeGroups.length; x++) {
reSubscribeCollege(activeCollegeGroups[x].contactId);
}
return {
body: JSON.stringify({
result: "success"
}),
};
},

});

async function reSubscribeCollege(
contactId: string) {
let collegeGroup = {
unsubscribed: false
};
const update_college_URL =
urls.updateCollegeGroup() + "/" + contactId;
await axios.put(update_college_URL, collegeGroup, {
headers: urls.qualtricsHeader(),
});
}
2 changes: 1 addition & 1 deletion src/functions/send-reminder-invite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ app.http("send-reminder-invite", {
let activeCollegeGroups = (await getAllCollegeGroups()).filter(
(collegeGroup) =>
collegeGroup.embeddedData?.groupStatus == "Invited"
&& !collegeGroup.embeddedData?.unsubscribed
&& !collegeGroup?.unsubscribed
&& (collegeGroup.embeddedData.invitationAttempt == undefined || parseInt(collegeGroup.embeddedData.invitationAttempt) < 3)
&& moreThanOneWeek(currentDate, new Date(collegeGroup.embeddedData.dateInvited))
);
Expand Down
2 changes: 1 addition & 1 deletion src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export type College = Contact & {
};

export type CollegeGroup = Contact & {
unsubscribed?: string,
embeddedData?: {
unsubscribed?: string
groupName?: string;
jobTitle?: string;
dateInvited?: string;
Expand Down

0 comments on commit 06de710

Please sign in to comment.