11import axios , { AxiosInstance , AxiosRequestConfig , AxiosError } from 'axios'
2- import { User } from './type'
2+ import { User , Note , Team , CreateNoteOptions , NotePermissionRole , CommentPermissionType } from './type'
33
44export class API {
55 public axios : AxiosInstance
66 constructor ( accessToken : string ) {
77 this . axios = axios . create ( {
8- baseURL : "http://localhost:3000/v1/api " ,
8+ baseURL : "http://localhost:3000/v1" ,
99 headers :{
10- "Content-Type" : "application. json" ,
10+ "Content-Type" : "application/ json" ,
1111 }
1212 } )
13+
1314 this . axios . interceptors . request . use (
1415 ( config : AxiosRequestConfig ) => {
15- if ( ! config . headers ) {
16- config . headers = { } ;
17- }
18-
1916 if ( accessToken ) {
20- config . headers . Authorization = `Bearer ${ accessToken } ` ;
17+ config . headers ! . Authorization = `Bearer ${ accessToken } ` ;
2118 }
22-
2319 return config
2420 } ,
2521 ( err : AxiosError ) => {
@@ -29,13 +25,76 @@ export class API {
2925 }
3026
3127 getMe = async ( ) => {
32- const { data } = await this . axios . get < User > ( "/me" )
28+ const { data } = await this . axios . get < User > ( "me" )
29+ return data
30+ }
31+
32+ getHistory = async ( ) => {
33+ const { data } = await this . axios . get < Note [ ] > ( "history" )
34+ return data
35+ }
36+
37+ getNoteList = async ( ) => {
38+ const { data } = await this . axios . get < Note [ ] > ( "notes" )
39+ return data
40+ }
41+
42+ getNote = async ( noteId : string ) => {
43+ try {
44+ const { data } = await this . axios . get < Note > ( `notes/${ noteId } ` )
45+ return data
46+ } catch ( e ) {
47+ console . log ( e )
48+ }
49+ }
50+
51+ createNote = async ( options : CreateNoteOptions ) => {
52+ const { data } = await this . axios . post < Note > ( "notes" , options )
53+ return data
54+ }
55+
56+ updateNoteContent = async ( noteId : string , content ?: string ) => {
57+ const { data } = await this . axios . patch < string > ( `notes/${ noteId } ` , { content } )
3358 return data
3459 }
35- }
3660
37- const api = new API ( "60WUTLO5DIHIOHCIY9TO0QEDVATU55XBTE7JJJBX9UTG49M7Y1" )
38- api . getMe ( )
61+ deleteNote = async ( noteId : string ) => {
62+ try {
63+ const { data } = await this . axios . delete < void > ( `notes/${ noteId } ` )
64+ return data
65+ } catch ( e ) {
66+ }
67+ }
68+
69+ getTeams = async ( ) => {
70+ const { data } = await this . axios . get < Team [ ] > ( "teams" )
71+ return data
72+ }
73+
74+ getTeamNotes = async ( teamPath : string ) => {
75+ const { data} = await this . axios . get < Note [ ] > ( `teams/${ teamPath } /notes` )
76+ return data
77+ }
78+
79+ createTeamNote = async ( teamPath : string , options : CreateNoteOptions ) => {
80+ const { data } = await this . axios . post < Note > ( `teams/${ teamPath } /notes` , options )
81+ return data
82+ }
83+
84+ updateTeamNoteContent = async ( teamPath : string , noteId : string , content ?: string ) => {
85+ const { data } = await this . axios . patch < string > ( `notes/${ noteId } ` , { content } )
86+ return data
87+ }
88+
89+ deleteTeamNote = async ( teamPath : string , noteId : string ) => {
90+ try {
91+ const { data } = await this . axios . delete < void > ( `teams/${ teamPath } /notes/${ noteId } ` )
92+ console . log ( data )
93+ return data
94+ } catch ( e ) {
95+ }
96+ }
97+ }
3998
4099
41100
0 commit comments