1- import Project from "../resources/Project" ;
21import axios from "axios" ;
32import { AuthHeader , ProjectCollaborator } from "../definitions" ;
4- import {
5- APIProjectObject ,
6- ProjectModule ,
7- UserCreatedProject ,
8- } from "../definitions" ;
3+ import { APIProjectObject , ProjectModule } from "../definitions" ;
94
105const projectClientModule = ( headers : AuthHeader ) : ProjectModule => {
116 async function getOneJSON ( id : number | string , headers : AuthHeader ) {
12- return await axios
13- . get ( `https://api.todoist.com/rest/v1/projects/${ id } ` , {
14- headers,
15- } )
16- . then ( ( res ) => res . data as APIProjectObject ) ;
7+ let { data } = await axios . get (
8+ `https://api.todoist.com/rest/v1/projects/${ id } ` ,
9+ { headers }
10+ ) ;
11+ return data as APIProjectObject ;
1712 }
1813
1914 async function getAllJSON ( headers : AuthHeader ) {
20- return await axios
21- . get ( `https://api.todoist.com/rest/v1/projects` , {
22- headers,
23- } )
24- . then ( ( res ) => res . data as APIProjectObject [ ] ) ;
15+ let { data } = await axios . get ( `https://api.todoist.com/rest/v1/projects` , {
16+ headers,
17+ } ) ;
18+ return data as APIProjectObject [ ] ;
2519 }
2620
2721 return {
2822 create : async ( project ) => {
29- if ( ! ( < UserCreatedProject > project ?. name ) ) project = Project ( project ) ;
30-
31- return await axios
32- . post ( `https://api.todoist.com/rest/v1/projects` , project , {
33- headers,
34- } )
35- . then ( ( res ) => res . data as APIProjectObject ) ;
23+ let { data } = await axios . post (
24+ `https://api.todoist.com/rest/v1/projects` ,
25+ project ,
26+ { headers }
27+ ) ;
28+ return data as APIProjectObject ;
3629 } ,
3730
3831 getAll : async ( ) => {
@@ -54,29 +47,23 @@ const projectClientModule = (headers: AuthHeader): ProjectModule => {
5447 getCollaborators : async ( id ) => {
5548 const { data } = await axios . get (
5649 `https://api.todoist.com/rest/v1/projects/${ id } /collaborators` ,
57- {
58- headers,
59- }
50+ { headers }
6051 ) ;
6152 return data as ProjectCollaborator [ ] ;
6253 } ,
6354
6455 delete : async ( id ) => {
6556 return await axios . delete (
6657 `https://api.todoist.com/rest/v1/projects/${ id } ` ,
67- {
68- headers,
69- }
58+ { headers }
7059 ) ;
7160 } ,
7261
7362 update : async ( id , project ) => {
7463 return await axios . post (
7564 `https://api.todoist.com/rest/v1/projects/${ id } ` ,
7665 project ,
77- {
78- headers,
79- }
66+ { headers }
8067 ) ;
8168 } ,
8269 } ;
0 commit comments