1
1
import axios , { AxiosInstance , AxiosRequestConfig , AxiosError , AxiosResponse } from 'axios'
2
- import { User , Note , Team , CreateNoteOptions } from './type'
2
+ import { User , Note , Team , CreateNoteOptions , GetMe , GetUserHistory , GetUserNotes , GetUserNote , CreateUserNote , GetUserTeams , GetTeamNotes , CreateTeamNote , DeleteUserNote , DeleteTeamNote , UpdateUserNote , SingleNote , UpdateTeamNote } from './type'
3
3
import * as HackMDErrors from './error'
4
4
5
5
export default class API {
@@ -53,63 +53,59 @@ export default class API {
53
53
)
54
54
}
55
55
56
- async getMe ( ) {
56
+ async getMe ( ) : Promise < GetMe > {
57
57
const { data } = await this . axios . get < User > ( "me" )
58
58
return data
59
59
}
60
60
61
- async getHistory ( ) {
61
+ async getHistory ( ) : Promise < GetUserHistory > {
62
62
const { data } = await this . axios . get < Note [ ] > ( "history" )
63
63
return data
64
64
}
65
65
66
- async getNoteList ( ) {
66
+ async getNoteList ( ) : Promise < GetUserNotes > {
67
67
const { data } = await this . axios . get < Note [ ] > ( "notes" )
68
68
return data
69
69
}
70
70
71
- async getNote ( noteId : string ) {
72
- const { data } = await this . axios . get < Note > ( `notes/${ noteId } ` )
71
+ async getNote ( noteId : string ) : Promise < GetUserNote > {
72
+ const { data } = await this . axios . get < SingleNote > ( `notes/${ noteId } ` )
73
73
return data
74
74
}
75
75
76
- async createNote ( options : CreateNoteOptions ) {
77
- const { data } = await this . axios . post < Note > ( "notes" , options )
76
+ async createNote ( options : CreateNoteOptions ) : Promise < CreateUserNote > {
77
+ const { data } = await this . axios . post < SingleNote > ( "notes" , options )
78
78
return data
79
79
}
80
80
81
- async updateNoteContent ( noteId : string , content ?: string ) {
82
- const { data } = await this . axios . patch < string > ( `notes/${ noteId } ` , { content } )
83
- return data
81
+ async updateNoteContent ( noteId : string , content ?: string ) : Promise < UpdateUserNote > {
82
+ await this . axios . patch < AxiosResponse > ( `notes/${ noteId } ` , { content } )
84
83
}
85
84
86
- async deleteNote ( noteId : string ) {
87
- const { data } = await this . axios . delete < void > ( `notes/${ noteId } ` )
88
- return data
85
+ async deleteNote ( noteId : string ) : Promise < DeleteUserNote > {
86
+ await this . axios . delete < AxiosResponse > ( `notes/${ noteId } ` )
89
87
}
90
88
91
- async getTeams ( ) {
89
+ async getTeams ( ) : Promise < GetUserTeams > {
92
90
const { data } = await this . axios . get < Team [ ] > ( "teams" )
93
91
return data
94
92
}
95
93
96
- async getTeamNotes ( teamPath : string ) {
97
- const { data} = await this . axios . get < Note [ ] > ( `teams/${ teamPath } /notes` )
94
+ async getTeamNotes ( teamPath : string ) : Promise < GetTeamNotes > {
95
+ const { data } = await this . axios . get < Note [ ] > ( `teams/${ teamPath } /notes` )
98
96
return data
99
97
}
100
98
101
- async createTeamNote ( teamPath : string , options : CreateNoteOptions ) {
102
- const { data } = await this . axios . post < Note > ( `teams/${ teamPath } /notes` , options )
99
+ async createTeamNote ( teamPath : string , options : CreateNoteOptions ) : Promise < CreateTeamNote > {
100
+ const { data } = await this . axios . post < SingleNote > ( `teams/${ teamPath } /notes` , options )
103
101
return data
104
102
}
105
103
106
- async updateTeamNoteContent ( teamPath : string , noteId : string , content ?: string ) {
107
- const { data } = await this . axios . patch < string > ( `teams/${ teamPath } /notes/${ noteId } ` , { content } )
108
- return data
104
+ async updateTeamNoteContent ( teamPath : string , noteId : string , content ?: string ) : Promise < UpdateTeamNote > {
105
+ await this . axios . patch < AxiosResponse > ( `teams/${ teamPath } /notes/${ noteId } ` , { content } )
109
106
}
110
107
111
- async deleteTeamNote ( teamPath : string , noteId : string ) {
112
- const { data } = await this . axios . delete < void > ( `teams/${ teamPath } /notes/${ noteId } ` )
113
- return data
108
+ async deleteTeamNote ( teamPath : string , noteId : string ) : Promise < DeleteTeamNote > {
109
+ await this . axios . delete < AxiosResponse > ( `teams/${ teamPath } /notes/${ noteId } ` )
114
110
}
115
111
}
0 commit comments