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

Consolidated shared schedule deletion functions #15

Merged
merged 16 commits into from
Mar 31, 2024
2 changes: 2 additions & 0 deletions functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"format": "prettier \"**/*.{js,jsx,ts,tsx,json}\" --write",
"format:check": "prettier \"**/*.{js,jsx,ts,tsx,json}\" -l",
"build": "tsc",
"build:watch": "tsc -w",
"serve": "npm run build && firebase emulators:start --project dev --only functions",
"serve:debug": "npm run build && firebase emulators:start --project dev --only functions --inspect-functions",
"shell": "npm run build && firebase functions:shell --project dev",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
Expand Down
8 changes: 5 additions & 3 deletions functions/src/create_friend_invitation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,14 @@ export const createFriendInvitation = functions.https.onRequest(
.json(apiError("Email does not exist in database"));
}

const sortedVersions = versions.sort();

// find and delete existing invites for the same sender, friend, term, and version
const existingInvites = await invitesCollection
.where("sender", "==", senderId)
.where("friend", "==", friendId)
.where("term", "==", term)
.where("versions", "==", versions)
.where("versions", "==", sortedVersions)
.where("link", "==", false)
.get();
const batch = firestore.batch();
Expand All @@ -123,7 +125,7 @@ export const createFriendInvitation = functions.https.onRequest(
const record: FriendEmailInviteData = {
sender: senderId,
term,
versions,
versions: sortedVersions,
created: admin.firestore.Timestamp.fromDate(new Date()),
link: false,
validFor: 7 * 24 * 60 * 60,
Expand All @@ -133,7 +135,7 @@ export const createFriendInvitation = functions.https.onRequest(
try {
// Add the invite data to the schedule of the sender
const addRes = await invitesCollection.add(record);
versions.forEach((v) => {
sortedVersions.forEach((v) => {
if (!senderData.terms[term].versions[v].friends) {
senderData.terms[term].versions[v].friends = {};
}
Expand Down
6 changes: 4 additions & 2 deletions functions/src/create_friend_invitation_link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@ export const createFriendInvitationLink = functions.https.onRequest(
.json(apiError("Cannot make link for invalid schedule version"));
}

const sortedVersions = versions.sort();

// find and delete existing links for the same sender, term, and version
const existingInvites = await invitesCollection
.where("sender", "==", senderId)
.where("term", "==", term)
.where("versions", "==", versions)
.where("versions", "==", sortedVersions)
.where("link", "==", true)
.where("validFor", "==", validFor)
.get();
Expand All @@ -99,7 +101,7 @@ export const createFriendInvitationLink = functions.https.onRequest(
const record: FriendInviteData = {
sender: senderId,
term,
versions,
versions: sortedVersions,
created: admin.firestore.Timestamp.fromDate(new Date()),
link: true,
validFor,
Expand Down
130 changes: 0 additions & 130 deletions functions/src/delete_invitation_from_friend.ts

This file was deleted.

100 changes: 0 additions & 100 deletions functions/src/delete_invitation_from_sender.ts

This file was deleted.

Loading
Loading