Skip to content

Commit c0a986c

Browse files
feat: Adds new shared labels endpoints and functions
1 parent 349de65 commit c0a986c

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

src/TodoistApi.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import {
2424
UpdateSectionArgs,
2525
UpdateTaskArgs,
2626
QuickAddTaskArgs,
27+
RenameSharedLabelArgs,
28+
RemoveSharedLabelArgs,
2729
} from './types/requests'
2830
import { request, isSuccess } from './restClient'
2931
import { getTaskFromQuickAddResponse } from './utils/taskConverters'
@@ -39,6 +41,9 @@ import {
3941
ENDPOINT_REST_PROJECT_COLLABORATORS,
4042
ENDPOINT_REST_SECTIONS,
4143
ENDPOINT_REST_COMMENTS,
44+
ENDPOINT_REST_LABELS_SHARED,
45+
ENDPOINT_REST_LABELS_SHARED_RENAME,
46+
ENDPOINT_REST_LABELS_SHARED_REMOVE,
4247
} from './consts/endpoints'
4348
import {
4449
validateComment,
@@ -313,6 +318,9 @@ export class TodoistApi {
313318
return isSuccess(response)
314319
}
315320

321+
/**
322+
* Fetches a personal label
323+
*/
316324
async getLabel(id: number): Promise<Label> {
317325
Int.check(id)
318326
const response = await request<Label>(
@@ -325,6 +333,9 @@ export class TodoistApi {
325333
return validateLabel(response.data)
326334
}
327335

336+
/**
337+
* Fetches the personal labels
338+
*/
328339
async getLabels(): Promise<Label[]> {
329340
const response = await request<Label[]>(
330341
'GET',
@@ -336,6 +347,9 @@ export class TodoistApi {
336347
return validateLabelArray(response.data)
337348
}
338349

350+
/**
351+
* Adds a personal label
352+
*/
339353
async addLabel(args: AddLabelArgs, requestId?: string): Promise<Label> {
340354
const response = await request<Label>(
341355
'POST',
@@ -349,6 +363,9 @@ export class TodoistApi {
349363
return validateLabel(response.data)
350364
}
351365

366+
/**
367+
* Updates a personal label
368+
*/
352369
async updateLabel(id: number, args: UpdateLabelArgs, requestId?: string): Promise<boolean> {
353370
Int.check(id)
354371
const response = await request(
@@ -362,6 +379,9 @@ export class TodoistApi {
362379
return isSuccess(response)
363380
}
364381

382+
/**
383+
* Deletes a personal label
384+
*/
365385
async deleteLabel(id: number, requestId?: string): Promise<boolean> {
366386
Int.check(id)
367387
const response = await request(
@@ -375,6 +395,37 @@ export class TodoistApi {
375395
return isSuccess(response)
376396
}
377397

398+
async getSharedLabels(): Promise<string[]> {
399+
const response = await request<string[]>(
400+
'GET',
401+
API_REST_BASE_URI,
402+
ENDPOINT_REST_LABELS_SHARED,
403+
this.authToken,
404+
)
405+
406+
return response.data
407+
}
408+
409+
async renameSharedLabel(args: RenameSharedLabelArgs): Promise<void> {
410+
await request<void>(
411+
'POST',
412+
API_REST_BASE_URI,
413+
ENDPOINT_REST_LABELS_SHARED_RENAME,
414+
this.authToken,
415+
args,
416+
)
417+
}
418+
419+
async removeSharedLabel(args: RemoveSharedLabelArgs): Promise<void> {
420+
await request<void>(
421+
'POST',
422+
API_REST_BASE_URI,
423+
ENDPOINT_REST_LABELS_SHARED_REMOVE,
424+
this.authToken,
425+
args,
426+
)
427+
}
428+
378429
async getComments(args: GetTaskCommentsArgs | GetProjectCommentsArgs): Promise<Comment[]> {
379430
const response = await request<Comment[]>(
380431
'GET',

src/consts/endpoints.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ export const ENDPOINT_REST_TASKS = 'tasks'
66
export const ENDPOINT_REST_PROJECTS = 'projects'
77
export const ENDPOINT_REST_SECTIONS = 'sections'
88
export const ENDPOINT_REST_LABELS = 'labels'
9+
export const ENDPOINT_REST_LABELS_SHARED = ENDPOINT_REST_LABELS + '/shared'
10+
export const ENDPOINT_REST_LABELS_SHARED_RENAME = ENDPOINT_REST_LABELS_SHARED + '/rename'
11+
export const ENDPOINT_REST_LABELS_SHARED_REMOVE = ENDPOINT_REST_LABELS_SHARED + '/remove'
912
export const ENDPOINT_REST_COMMENTS = 'comments'
1013
export const ENDPOINT_REST_TASK_CLOSE = 'close'
1114
export const ENDPOINT_REST_TASK_REOPEN = 'reopen'

0 commit comments

Comments
 (0)