@@ -156,23 +156,6 @@ export const exportSessions = async (
156156export 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 ,
0 commit comments