Skip to content
Open
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
12 changes: 6 additions & 6 deletions functions/src/cohort.endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,16 @@ export const deleteCohort = onCall(async (request) => {
return {success: false};
}

// Delete document
const doc = app
.firestore()
.doc(`experiments/${data.experimentId}/cohorts/${data.cohortId}`);
app.firestore().recursiveDelete(doc);

// Set all participants in cohort to deleted
await markCohortParticipantsAsDeleted(data.experimentId, data.cohortId);

// TODO: Set all mediators in cohort to deleted

// Delete document (after marking participants, to avoid race conditions)
const doc = app
.firestore()
.doc(`experiments/${data.experimentId}/cohorts/${data.cohortId}`);
await app.firestore().recursiveDelete(doc);

return {success: true};
});
8 changes: 5 additions & 3 deletions functions/src/participant.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,11 @@ export async function updateCohortStageUnlocked(
.collection('cohorts')
.doc(cohortId);

const cohortConfig = (await cohortDoc.get()).data() as CohortConfig;
if (cohortConfig.stageUnlockMap[stageId]) {
return; // already marked as true
const cohortConfig = (await cohortDoc.get()).data() as
| CohortConfig
| undefined;
if (!cohortConfig || cohortConfig.stageUnlockMap[stageId]) {
return; // cohort deleted or already unlocked
}

cohortConfig.stageUnlockMap[stageId] = true;
Expand Down
3 changes: 2 additions & 1 deletion utils/src/stages/chat_stage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,9 @@ export function createChatStagePublicData(
config: ChatStageConfig,
): ChatStagePublicData {
const id = config.id;
const discussions = config.discussions ?? [];
const currentDiscussionId =
config.discussions.length === 0 ? null : config.discussions[0].id;
discussions.length === 0 ? null : discussions[0].id;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I'm pretty sure one could get away with the following one liner:

const currentDiscussionId = config.discussions?.[0]?.id ?? null;


return {
id,
Expand Down