Skip to content

Commit

Permalink
Merge pull request #156 from complexdatacollective/fix/createIntervie…
Browse files Browse the repository at this point in the history
…w-issue

Fix `createInterview` to support creating interview for externally specified participants
  • Loading branch information
jthrilly committed Jul 26, 2024
2 parents 5da5574 + 05a0bf6 commit 2abae3c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
40 changes: 23 additions & 17 deletions actions/interviews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,23 +156,6 @@ export const exportSessions = async (
export async function createInterview(data: CreateInterview) {
const { participantIdentifier, protocolId } = data;

/**
* If no participant identifier is provided, we check if anonymous recruitment is enabled.
* If it is, we create a new participant and use that identifier.
*/
const participantStatement = participantIdentifier
? {
connect: {
identifier: participantIdentifier,
},
}
: {
create: {
identifier: `p-${createId()}`,
label: 'Anonymous Participant',
},
};

try {
if (!participantIdentifier) {
const appSettings = await prisma.appSettings.findFirst();
Expand All @@ -185,6 +168,29 @@ export async function createInterview(data: CreateInterview) {
}
}

/**
* If a participant identifier is provided, we attempt to connect to an existing participant
* or create a new one with that identifier. If no participant identifier is provided,
* we create a new anonymous participant with a generated identifier.
*/
const participantStatement = participantIdentifier
? {
connectOrCreate: {
create: {
identifier: participantIdentifier,
},
where: {
identifier: participantIdentifier,
},
},
}
: {
create: {
identifier: `p-${createId()}`,
label: 'Anonymous Participant',
},
};

const createdInterview = await prisma.interview.create({
select: {
participant: true,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fresco",
"version": "1.0.0",
"version": "1.0.1",
"private": true,
"type": "module",
"packageManager": "[email protected]+sha256.9551e803dcb7a1839fdf5416153a844060c7bce013218ce823410532504ac10b",
Expand Down

0 comments on commit 2abae3c

Please sign in to comment.