1
1
import { String } from 'runtypes'
2
- import {
3
- Task ,
4
- QuickAddTaskResponse ,
5
- Project ,
6
- Label ,
7
- User ,
8
- Section ,
9
- Comment ,
10
- } from './types/entities'
2
+ import { Task , QuickAddTaskResponse , Project , Label , Section , Comment } from './types/entities'
11
3
import {
12
4
AddCommentArgs ,
13
5
AddLabelArgs ,
@@ -28,8 +20,15 @@ import {
28
20
RemoveSharedLabelArgs ,
29
21
GetProjectsArgs ,
30
22
GetProjectCollaboratorsArgs ,
31
- GetSections ,
32
23
GetLabelsArgs ,
24
+ GetLabelsResponse ,
25
+ GetTasksResponse ,
26
+ GetProjectsResponse ,
27
+ GetProjectCollaboratorsResponse ,
28
+ GetSectionsArgs ,
29
+ GetSectionsResponse ,
30
+ GetSharedLabelsResponse ,
31
+ GetCommentsResponse ,
33
32
} from './types/requests'
34
33
import { request , isSuccess } from './restClient'
35
34
import { getTaskFromQuickAddResponse } from './utils/taskConverters'
@@ -93,16 +92,16 @@ export class TodoistApi {
93
92
return validateTask ( response . data )
94
93
}
95
94
96
- async getTasks ( args : GetTasksArgs = { } ) : Promise < {
97
- results : Task [ ]
98
- nextCursor : string | null
99
- } > {
95
+ async getTasks ( args : GetTasksArgs = { } ) : Promise < GetTasksResponse > {
100
96
const {
101
97
data : { results, nextCursor } ,
102
- } = await request < {
103
- results : Task [ ]
104
- nextCursor : string | null
105
- } > ( 'GET' , this . syncApiBase , ENDPOINT_REST_TASKS , this . authToken , args )
98
+ } = await request < GetTasksResponse > (
99
+ 'GET' ,
100
+ this . syncApiBase ,
101
+ ENDPOINT_REST_TASKS ,
102
+ this . authToken ,
103
+ args ,
104
+ )
106
105
107
106
return {
108
107
results : validateTaskArray ( results ) ,
@@ -201,12 +200,10 @@ export class TodoistApi {
201
200
return validateProject ( response . data )
202
201
}
203
202
204
- async getProjects (
205
- args : GetProjectsArgs = { } ,
206
- ) : Promise < { results : Project [ ] ; nextCursor : string | null } > {
203
+ async getProjects ( args : GetProjectsArgs = { } ) : Promise < GetProjectsResponse > {
207
204
const {
208
205
data : { results, nextCursor } ,
209
- } = await request < { results : Project [ ] ; nextCursor : string | null } > (
206
+ } = await request < GetProjectsResponse > (
210
207
'GET' ,
211
208
this . syncApiBase ,
212
209
ENDPOINT_REST_PROJECTS ,
@@ -262,11 +259,11 @@ export class TodoistApi {
262
259
async getProjectCollaborators (
263
260
projectId : string ,
264
261
args : GetProjectCollaboratorsArgs = { } ,
265
- ) : Promise < { results : User [ ] ; nextCursor : string | null } > {
262
+ ) : Promise < GetProjectCollaboratorsResponse > {
266
263
String . check ( projectId )
267
264
const {
268
265
data : { results, nextCursor } ,
269
- } = await request < { results : User [ ] ; nextCursor : string | null } > (
266
+ } = await request < GetProjectCollaboratorsResponse > (
270
267
'GET' ,
271
268
this . syncApiBase ,
272
269
generatePath ( ENDPOINT_REST_PROJECTS , projectId , ENDPOINT_REST_PROJECT_COLLABORATORS ) ,
@@ -280,12 +277,10 @@ export class TodoistApi {
280
277
}
281
278
}
282
279
283
- async getSections (
284
- args : GetSections ,
285
- ) : Promise < { results : Section [ ] ; nextCursor : string | null } > {
280
+ async getSections ( args : GetSectionsArgs ) : Promise < GetSectionsResponse > {
286
281
const {
287
282
data : { results, nextCursor } ,
288
- } = await request < { results : Section [ ] ; nextCursor : string | null } > (
283
+ } = await request < GetSectionsResponse > (
289
284
'GET' ,
290
285
this . syncApiBase ,
291
286
ENDPOINT_REST_SECTIONS ,
@@ -368,12 +363,10 @@ export class TodoistApi {
368
363
/**
369
364
* Fetches the personal labels
370
365
*/
371
- async getLabels (
372
- args : GetLabelsArgs = { } ,
373
- ) : Promise < { results : Label [ ] ; nextCursor : string | null } > {
366
+ async getLabels ( args : GetLabelsArgs = { } ) : Promise < GetLabelsResponse > {
374
367
const {
375
368
data : { results, nextCursor : nextCursor } ,
376
- } = await request < { results : Label [ ] ; nextCursor : string | null } > (
369
+ } = await request < GetLabelsResponse > (
377
370
'GET' ,
378
371
this . syncApiBase ,
379
372
ENDPOINT_REST_LABELS ,
@@ -435,12 +428,10 @@ export class TodoistApi {
435
428
return isSuccess ( response )
436
429
}
437
430
438
- async getSharedLabels (
439
- args ?: GetSharedLabelsArgs ,
440
- ) : Promise < { results : string [ ] ; nextCursor : string | null } > {
431
+ async getSharedLabels ( args ?: GetSharedLabelsArgs ) : Promise < GetSharedLabelsResponse > {
441
432
const {
442
433
data : { results, nextCursor : nextCursor } ,
443
- } = await request < { results : string [ ] ; nextCursor : string | null } > (
434
+ } = await request < GetSharedLabelsResponse > (
444
435
'GET' ,
445
436
this . syncApiBase ,
446
437
ENDPOINT_REST_LABELS_SHARED ,
@@ -477,10 +468,10 @@ export class TodoistApi {
477
468
478
469
async getComments (
479
470
args : GetTaskCommentsArgs | GetProjectCommentsArgs ,
480
- ) : Promise < { results : Comment [ ] ; nextCursor : string | null } > {
471
+ ) : Promise < GetCommentsResponse > {
481
472
const {
482
473
data : { results, nextCursor } ,
483
- } = await request < { results : Comment [ ] ; nextCursor : string | null } > (
474
+ } = await request < GetCommentsResponse > (
484
475
'GET' ,
485
476
this . syncApiBase ,
486
477
ENDPOINT_REST_COMMENTS ,
0 commit comments