Skip to content

Commit 2abae3c

Browse files
authored
Merge pull request #156 from complexdatacollective/fix/createInterview-issue
Fix `createInterview` to support creating interview for externally specified participants
2 parents 5da5574 + 05a0bf6 commit 2abae3c

2 files changed

Lines changed: 24 additions & 18 deletions

File tree

actions/interviews.ts

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -156,23 +156,6 @@ export const exportSessions = async (
156156
export async function createInterview(data: CreateInterview) {
157157
const { participantIdentifier, protocolId } = data;
158158

159-
/**
160-
* If no participant identifier is provided, we check if anonymous recruitment is enabled.
161-
* If it is, we create a new participant and use that identifier.
162-
*/
163-
const participantStatement = participantIdentifier
164-
? {
165-
connect: {
166-
identifier: participantIdentifier,
167-
},
168-
}
169-
: {
170-
create: {
171-
identifier: `p-${createId()}`,
172-
label: 'Anonymous Participant',
173-
},
174-
};
175-
176159
try {
177160
if (!participantIdentifier) {
178161
const appSettings = await prisma.appSettings.findFirst();
@@ -185,6 +168,29 @@ export async function createInterview(data: CreateInterview) {
185168
}
186169
}
187170

171+
/**
172+
* If a participant identifier is provided, we attempt to connect to an existing participant
173+
* or create a new one with that identifier. If no participant identifier is provided,
174+
* we create a new anonymous participant with a generated identifier.
175+
*/
176+
const participantStatement = participantIdentifier
177+
? {
178+
connectOrCreate: {
179+
create: {
180+
identifier: participantIdentifier,
181+
},
182+
where: {
183+
identifier: participantIdentifier,
184+
},
185+
},
186+
}
187+
: {
188+
create: {
189+
identifier: `p-${createId()}`,
190+
label: 'Anonymous Participant',
191+
},
192+
};
193+
188194
const createdInterview = await prisma.interview.create({
189195
select: {
190196
participant: true,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fresco",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"private": true,
55
"type": "module",
66
"packageManager": "pnpm@9.1.1+sha256.9551e803dcb7a1839fdf5416153a844060c7bce013218ce823410532504ac10b",

0 commit comments

Comments
 (0)