11import 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'
33import * as HackMDErrors from './error'
44
55export default class API {
@@ -53,63 +53,59 @@ export default class API {
5353 )
5454 }
5555
56- async getMe ( ) {
56+ async getMe ( ) : Promise < GetMe > {
5757 const { data } = await this . axios . get < User > ( "me" )
5858 return data
5959 }
6060
61- async getHistory ( ) {
61+ async getHistory ( ) : Promise < GetUserHistory > {
6262 const { data } = await this . axios . get < Note [ ] > ( "history" )
6363 return data
6464 }
6565
66- async getNoteList ( ) {
66+ async getNoteList ( ) : Promise < GetUserNotes > {
6767 const { data } = await this . axios . get < Note [ ] > ( "notes" )
6868 return data
6969 }
7070
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 } ` )
7373 return data
7474 }
7575
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 )
7878 return data
7979 }
8080
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 } )
8483 }
8584
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 } ` )
8987 }
9088
91- async getTeams ( ) {
89+ async getTeams ( ) : Promise < GetUserTeams > {
9290 const { data } = await this . axios . get < Team [ ] > ( "teams" )
9391 return data
9492 }
9593
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` )
9896 return data
9997 }
10098
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 )
103101 return data
104102 }
105103
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 } )
109106 }
110107
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 } ` )
114110 }
115111}
0 commit comments