Skip to content

Commit

Permalink
More debugging statements
Browse files Browse the repository at this point in the history
  • Loading branch information
nriedman committed Apr 17, 2024
1 parent 4a31f4d commit a1e74a9
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "84060c25a97a757bf3045128a2563021282283c70a9cb6009941a41298deef92",
"originHash" : "7a1ae4cd835f2e84578822a40fc673f29fc7ab26c0416a0079ce8402bbb3da0b",
"pins" : [
{
"identity" : "abseil-cpp-binary",
Expand Down Expand Up @@ -190,6 +190,15 @@
"version" : "1.2.2"
}
},
{
"identity" : "spezibluetooth",
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordSpezi/SpeziBluetooth.git",
"state" : {
"revision" : "3178bc1184dc6636e8112694e09fdfca7cbcf7d7",
"version" : "1.0.2"
}
},
{
"identity" : "spezicontact",
"kind" : "remoteSourceControl",
Expand All @@ -199,6 +208,15 @@
"version" : "1.0.0"
}
},
{
"identity" : "spezifileformats",
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordSpezi/SpeziFileFormats",
"state" : {
"revision" : "017ea997f4f6128b15e8b8d4aac979cb7a822e74",
"version" : "1.2.0"
}
},
{
"identity" : "spezifirebase",
"kind" : "remoteSourceControl",
Expand Down Expand Up @@ -280,6 +298,15 @@
"version" : "1.2.3"
}
},
{
"identity" : "swift-atomics",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-atomics.git",
"state" : {
"revision" : "cd142fd2f64be2100422d658e7411e39489da985",
"version" : "1.2.0"
}
},
{
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
Expand All @@ -289,6 +316,15 @@
"version" : "1.1.0"
}
},
{
"identity" : "swift-nio",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio.git",
"state" : {
"revision" : "fc63f0cf4e55a4597407a9fc95b16a2bc44b4982",
"version" : "2.64.0"
}
},
{
"identity" : "swift-package-list",
"kind" : "remoteSourceControl",
Expand Down Expand Up @@ -316,6 +352,15 @@
"version" : "509.0.2"
}
},
{
"identity" : "swift-system",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-system.git",
"state" : {
"revision" : "025bcb1165deab2e20d4eaba79967ce73013f496",
"version" : "1.2.1"
}
},
{
"identity" : "swiftlint",
"kind" : "remoteSourceControl",
Expand Down
5 changes: 5 additions & 0 deletions functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,27 @@ exports.checkInvitationCode = onCall(async (request) => {

try {
// Based on https://github.com/StanfordSpezi/SpeziStudyApplication/blob/main/functions/index.js
logger.debug("Fetching invitation code document");
const invitationCodeRef = firestore.doc(`invitationCodes/${invitationCode}`);
const invitationCodeDoc = await invitationCodeRef.get();
logger.debug(`Found invitation code document: ${invitationCodeDoc.exists}`);

if (!invitationCodeDoc.exists || (invitationCodeDoc.data().used)) {
logger.warn(`Invitation code not found or already used: ${invitationCode}`);
throw new https.HttpsError("not-found", "Invitation code not found or already used.");
}

logger.debug("Getting user study document")
const userStudyRef = firestore.doc(`users/${userId}`);
const userStudyDoc = await userStudyRef.get();
logger.debug("Finished getting user study document")

if (userStudyDoc.exists) {
logger.warn(`User (${userId}) is already enrolled in the study.`);
throw new https.HttpsError("already-exists", "User is already enrolled in the study.");
}

logger.debug("Transaction: Enrolling user in study");
await firestore.runTransaction(async (transaction) => {
transaction.set(userStudyRef, {
invitationCode: invitationCode,
Expand Down

0 comments on commit a1e74a9

Please sign in to comment.