Skip to content

Commit 00d4266

Browse files
authored
feat: Added GetArchivedProjects API Endpoint (#328)
1 parent 1520ddb commit 00d4266

File tree

5 files changed

+81
-2
lines changed

5 files changed

+81
-2
lines changed

src/TodoistApi.projects.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,5 +270,37 @@ describe('TodoistApi project endpoints', () => {
270270
const project = await api.unarchiveProject('123')
271271
expect(project).toEqual(DEFAULT_PROJECT)
272272
})
273+
274+
describe('getArchivedProjects', () => {
275+
test('calls get on archived projects endpoint', async () => {
276+
const requestMock = setupRestClientMock({
277+
results: [DEFAULT_PROJECT],
278+
nextCursor: 'abc',
279+
})
280+
const api = getTarget()
281+
282+
const args = { limit: 10, cursor: '0' }
283+
await api.getArchivedProjects(args)
284+
285+
expect(requestMock).toHaveBeenCalledTimes(1)
286+
expect(requestMock).toHaveBeenCalledWith(
287+
'GET',
288+
getSyncBaseUri(),
289+
'projects/archived',
290+
DEFAULT_AUTH_TOKEN,
291+
args,
292+
)
293+
})
294+
295+
test('returns result from rest client', async () => {
296+
const projects = [DEFAULT_PROJECT, PROJECT_WITH_OPTIONALS_AS_NULL]
297+
setupRestClientMock({ results: projects, nextCursor: 'abc' })
298+
const api = getTarget()
299+
300+
const { results, nextCursor } = await api.getArchivedProjects()
301+
expect(results).toEqual(projects)
302+
expect(nextCursor).toBe('abc')
303+
})
304+
})
273305
})
274306
})

src/TodoistApi.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import {
3333
GetCompletedTasksByCompletionDateArgs,
3434
GetCompletedTasksByDueDateArgs,
3535
GetCompletedTasksResponse,
36+
GetArchivedProjectsArgs,
37+
GetArchivedProjectsResponse,
3638
} from './types/requests'
3739
import { request, isSuccess } from './restClient'
3840
import {
@@ -55,6 +57,7 @@ import {
5557
ENDPOINT_SYNC,
5658
PROJECT_ARCHIVE,
5759
PROJECT_UNARCHIVE,
60+
ENDPOINT_REST_PROJECTS_ARCHIVED,
5861
} from './consts/endpoints'
5962
import {
6063
validateComment,
@@ -458,6 +461,31 @@ export class TodoistApi {
458461
}
459462
}
460463

464+
/**
465+
* Retrieves all archived projects with optional filters.
466+
*
467+
* @param args - Optional filters for retrieving archived projects.
468+
* @returns A promise that resolves to an array of archived projects.
469+
*/
470+
async getArchivedProjects(
471+
args: GetArchivedProjectsArgs = {},
472+
): Promise<GetArchivedProjectsResponse> {
473+
const {
474+
data: { results, nextCursor },
475+
} = await request<GetArchivedProjectsResponse>(
476+
'GET',
477+
this.syncApiBase,
478+
ENDPOINT_REST_PROJECTS_ARCHIVED,
479+
this.authToken,
480+
args,
481+
)
482+
483+
return {
484+
results: validateProjectArray(results),
485+
nextCursor,
486+
}
487+
}
488+
461489
/**
462490
* Creates a new project with the provided parameters.
463491
*

src/consts/endpoints.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export const ENDPOINT_REST_TASKS_COMPLETED_BY_COMPLETION_DATE =
2323
ENDPOINT_REST_TASKS + '/completed/by_completion_date'
2424
export const ENDPOINT_REST_TASKS_COMPLETED_BY_DUE_DATE =
2525
ENDPOINT_REST_TASKS + '/completed/by_due_date'
26-
export const ENDPOINT_REST_PROJECTS = 'projects'
2726
export const ENDPOINT_REST_SECTIONS = 'sections'
2827
export const ENDPOINT_REST_LABELS = 'labels'
2928
export const ENDPOINT_REST_LABELS_SHARED = ENDPOINT_REST_LABELS + '/shared'
@@ -32,6 +31,8 @@ export const ENDPOINT_REST_LABELS_SHARED_REMOVE = ENDPOINT_REST_LABELS_SHARED +
3231
export const ENDPOINT_REST_COMMENTS = 'comments'
3332
export const ENDPOINT_REST_TASK_CLOSE = 'close'
3433
export const ENDPOINT_REST_TASK_REOPEN = 'reopen'
34+
export const ENDPOINT_REST_PROJECTS = 'projects'
35+
export const ENDPOINT_REST_PROJECTS_ARCHIVED = ENDPOINT_REST_PROJECTS + '/archived'
3536
export const ENDPOINT_REST_PROJECT_COLLABORATORS = 'collaborators'
3637
export const PROJECT_ARCHIVE = 'archive'
3738
export const PROJECT_UNARCHIVE = 'unarchive'

src/types/entities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export const BaseProjectSchema = z.object({
104104
*/
105105
export const PersonalProjectSchema = BaseProjectSchema.extend({
106106
parentId: z.string().nullable(),
107-
inboxProject: z.boolean(),
107+
inboxProject: z.boolean().optional().default(false),
108108
}).transform((data) => {
109109
return {
110110
...data,

src/types/requests.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,24 @@ export type GetProjectsResponse = {
183183
nextCursor: string | null
184184
}
185185

186+
/**
187+
* Arguments for retrieving archived projects.
188+
* @see https://todoist.com/api/v1/docs#tag/Projects/operation/get_archived_projects_api_v1_projects_archived_get
189+
*/
190+
export type GetArchivedProjectsArgs = {
191+
cursor?: string | null
192+
limit?: number
193+
}
194+
195+
/**
196+
* Response from retrieving archived projects.
197+
* @see https://todoist.com/api/v1/docs#tag/Projects/operation/get_archived_projects_api_v1_projects_archived_get
198+
*/
199+
export type GetArchivedProjectsResponse = {
200+
results: (PersonalProject | WorkspaceProject)[]
201+
nextCursor: string | null
202+
}
203+
186204
/**
187205
* Arguments for creating a new project.
188206
* @see https://todoist.com/api/v1/docs#tag/Projects/operation/create_project_api_v1_projects_post

0 commit comments

Comments
 (0)