Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

## [2.0.9] - 2025-06-25

- Added `addResearcherAssistantToStudy` endpoint
- Added `getStudyResearcherAssistants` endpoint
- Added `removeResearcherAssistantFromStudy` endpoint
- Deprecated `addResearcherToStudy` and `removeResearcherFromStudy`.

## [2.0.8] - 2025-06-25

### Changed

- Added `is_descending` parameters to `getParticipantAccounts` endpoint

## [2.0.7] - 2025-06-11

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@carp-dk/client",
"type": "module",
"version": "2.0.7",
"version": "2.0.9",
"description": "TypeScript API client for the CARP Web Services (CAWS).",
"repository": {
"type": "git",
Expand Down
10 changes: 9 additions & 1 deletion src/endpoints/study/recruitment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,25 @@ class Recruitment extends Endpoint {
offset,
search,
response_as_dto,
is_descending,
}: {
studyId: string;
limit?: number | null;
offset?: number | null;
search?: string | null;
response_as_dto?: boolean | null;
is_descending?: boolean | null;
}) {
const response = await this.actions.get<
ParticipantAccount[] | PaginatedParticipantAccounts
>(`${this.wsEndpoint}/${studyId}/participants/accounts`, {
params: { limit, offset, search, response_as_dto },
params: {
limit,
offset,
search,
response_as_dto,
is_descending,
},
});

return response.data;
Expand Down
61 changes: 61 additions & 0 deletions src/endpoints/study/researchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Researchers extends Endpoint {
endpoint: string = "/api/studies";

/**
* @deprecated.
* Add researcher to a study
* @param studyId The ID of the study
* @param email The email of the researcher to add
Expand All @@ -28,6 +29,30 @@ class Researchers extends Endpoint {
);
}

/**
* Add researcher assistant to a study
* @param studyId The ID of the study
* @param email The email of the researcher assistant to add
*/
async addResearcherAssistantToStudy({
studyId,
email,
}: {
studyId: string;
email: string;
}) {
const query = new URLSearchParams({ email }).toString();
await this.actions.post(
`${this.endpoint}/${studyId}/researcher-assistants/add`,
query,
{
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
},
);
}

/**
* Get all researchers for a study
* @param studyId The ID of the study
Expand All @@ -41,6 +66,19 @@ class Researchers extends Endpoint {
}

/**
* Get all researcher assistants for a study
* @param studyId The ID of the study
* @returns The list of researcher assistants
*/
async getStudyResearcherAssistants({ studyId }: { studyId: string }) {
const response = await this.actions.get(
`${this.endpoint}/${studyId}/researcher-assistants`,
);
return response.data as User[];
}

/**
* @deprecated
* Remove a researcher from a study
* @param studyId The ID of the study
* @param email The email of the researcher to remove
Expand All @@ -62,6 +100,29 @@ class Researchers extends Endpoint {
},
);
}

/**
* Remove a researcher assistant from a study
* @param studyId The ID of the study
* @param email The email of the researcher to remove
*/
async removeResearcherAssistantFromStudy({
studyId,
email,
}: {
studyId: string;
email: string;
}) {
const query = new URLSearchParams({ email }).toString();
await this.actions.delete(
`${this.endpoint}/${studyId}/researcher-assistants?${query}`,
{
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
},
);
}
}

export default Researchers;
1 change: 1 addition & 0 deletions src/test/endpoints/study/recruitment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ describe("Recruitment", () => {
offset: 0,
search: null,
response_as_dto: true,
is_descending: false,
});

expect(accountInfo).toBeDefined();
Expand Down
39 changes: 39 additions & 0 deletions src/test/endpoints/study/study.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,25 @@ describe("Study", () => {
expect(researcher).not.toBe(undefined);
});

it("should be able to add a researcher assistant to a study", async () => {
await expect(
testClient.study.researchers.addResearcherAssistantToStudy({
studyId: study.studyId.stringRepresentation,
email: "[email protected]",
}),
).resolves.not.toThrow();
const researcherAssistants =
await testClient.study.researchers.getStudyResearcherAssistants({
studyId: study.studyId.stringRepresentation,
});

expect(researcherAssistants).toBeInstanceOf(Array);
const researcher = researcherAssistants.find(
(r) => r.email === "[email protected]",
);
expect(researcher).not.toBe(undefined);
});

it("should be able to remove a researcher from a study", async () => {
await expect(
testClient.study.researchers.removeResearcherFromStudy({
Expand All @@ -229,6 +248,26 @@ describe("Study", () => {
expect(researcher).toBe(undefined);
});

it("should be able to remove a researcher assistant from a study", async () => {
await expect(
testClient.study.researchers.removeResearcherAssistantFromStudy({
studyId: study.studyId.stringRepresentation,
email: "[email protected]",
}),
).resolves.not.toThrow();

const researcherAssistants =
await testClient.study.researchers.getStudyResearcherAssistants({
studyId: study.studyId.stringRepresentation,
});

expect(researcherAssistants).toBeInstanceOf(Array);
const researcherAssistant = researcherAssistants.find(
(r) => r.email === "[email protected]",
);
expect(researcherAssistant).toBe(undefined);
});

it("study should be able to go live", async () => {
const studyBefore = await testClient.study.getStatus({
studyId: study.studyId.stringRepresentation,
Expand Down
Loading