diff --git a/CHANGELOG.md b/CHANGELOG.md index b8a5641..fed04c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Added `getRedirectURIs` endpoint - Added `getDataStreamSummary` endpoint - Added `applicationData` parameter to `study.setInvitation` endpoint +- Added `response_as_dto` parameter to `getParticipantAccounts` endpoint ### Fixed diff --git a/src/endpoints/study/recruitment.ts b/src/endpoints/study/recruitment.ts index 0154209..18d290c 100644 --- a/src/endpoints/study/recruitment.ts +++ b/src/endpoints/study/recruitment.ts @@ -2,6 +2,7 @@ import { AnonymousLinksRequest, AnonymousLinksResponse, InactiveDeployment, + PaginatedParticipantAccounts, ParticipantAccount, ParticipantGroups, ParticipantInfo, @@ -79,16 +80,19 @@ class Recruitment extends Endpoint { limit, offset, search, + response_as_dto, }: { studyId: string; limit?: number | null; offset?: number | null; search?: string | null; + response_as_dto?: boolean | null; }) { - const response = await this.actions.get( - `${this.wsEndpoint}/${studyId}/participants/accounts`, - { params: { limit, offset, search } }, - ); + const response = await this.actions.get< + ParticipantAccount[] | PaginatedParticipantAccounts + >(`${this.wsEndpoint}/${studyId}/participants/accounts`, { + params: { limit, offset, search, response_as_dto }, + }); return response.data; } diff --git a/src/shared/models/studies.ts b/src/shared/models/studies.ts index dd2a703..390bcc1 100644 --- a/src/shared/models/studies.ts +++ b/src/shared/models/studies.ts @@ -134,6 +134,14 @@ export interface ParticipantAccount { username: string; } +export interface PaginatedParticipantAccounts { + limit: number; + offset: number; + total: number; + search: string; + participants: ParticipantAccount[]; +} + export interface Statistics { deployments: { deploymentId: string; uploads: any }[]; } diff --git a/src/test/endpoints/study/recruitment.test.ts b/src/test/endpoints/study/recruitment.test.ts index d651008..22fcf3b 100644 --- a/src/test/endpoints/study/recruitment.test.ts +++ b/src/test/endpoints/study/recruitment.test.ts @@ -7,6 +7,7 @@ import { StudyProtocolSnapshot, StudyStatus, getSerializer, + PaginatedParticipantAccounts, } from "@/shared"; import { generateRandomEmail, setupTestClient } from "@/test/utils"; import { CarpTestClient } from "@/client"; @@ -146,11 +147,13 @@ describe("Recruitment", () => { limit: 1, offset: 0, search: null, + response_as_dto: true, }); expect(accountInfo).toBeDefined(); - expect(accountInfo).toBeInstanceOf(Array); - expect(accountInfo.length).toBe(1); + expect( + (accountInfo as PaginatedParticipantAccounts).participants.length, + ).toBe(1); }); afterAll(async () => {