| 7 | import { User as UserInfo } from 'types/user'; |
| 8 | |
| 9 | export default class User implements UserService { |
| 10 | private api: Api; |
| 11 | private baseUrl = ''; |
| 12 | |
| 13 | constructor(baseApi: Api) { |
| 14 | this.api = baseApi; |
| 15 | } |
| 16 | |
| 17 | status: Status = () => { |
| 18 | return this.api.get(`${this.baseUrl}/status`) |
| 19 | .then((resp: AxiosResponse<UserInfo>) => resp.data); |
| 20 | }; |
| 21 | |
| 22 | login: Login = (username: string, password: string) => { |
| 23 | return this.api.post(`${this.baseUrl}/login`, { username, password }) |
| 24 | .then((resp: AxiosResponse<AuthToken>) => resp.data); |
| 25 | }; |
| 26 | |
| 27 | update: Update = (username: string, default_weight_unit: WeightUnit) => { |
| 28 | return this.api.put(`${this.baseUrl}/user`, { username, default_weight_unit }) |
| 29 | .then((resp: AxiosResponse<UserInfo>) => resp.data); |
| 30 | }; |
| 31 | |
| 32 | register: Register = (username: string, password: string, email: string) => { |
| 33 | return this.api.post(`${this.baseUrl}/register`, { username, password, email }) |
| 34 | .then((resp: AxiosResponse<AuthToken>) => resp.data); |
| 35 | }; |
| 36 | |
| 37 | requestReset: RequestReset = email => { |
| 38 | return this.api.post(`${this.baseUrl}/request-reset`, { email }) |
| 39 | .then((resp: AxiosResponse<null>) => resp.data); |
| 40 | }; |
| 41 | |
| 42 | resetPassword: ResetPassword = (callbackId: string, password: string) => { |
| 43 | return this.api.post(`${this.baseUrl}/reset-password`, { callbackId, password }) |
| 44 | .then((resp: AxiosResponse<null>) => resp.data); |
| 45 | } |
| 46 | } |