Skip to content
Open
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
16 changes: 16 additions & 0 deletions functions/src/participant.endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ export const createParticipant = onCall(async (request) => {
handleCreateParticipantValidationErrors(data);
}

// If prolificId is provided, check for an existing non-deleted participant
if (data.prolificId) {
const existing = await app
.firestore()
.collection(`experiments/${data.experimentId}/participants`)
.where('prolificId', '==', data.prolificId)
.get();

const existingParticipant = existing.docs
.map((doc) => doc.data() as ParticipantProfileExtended)
.find((p) => p.currentStatus !== ParticipantStatus.DELETED);
if (existingParticipant) {
return {id: existingParticipant.privateId};
}
}

// Create initial participant config
const participantConfig = createParticipantProfileExtended({
currentCohortId: data.cohortId,
Expand Down