🎉 First commit, from couchbase generator, basic changes

not tested / updated yet
This commit is contained in:
Sebastián Ramírez
2019-02-09 19:42:36 +04:00
commit 7f8bfc8faa
198 changed files with 21022 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
import axios from 'axios';
import { apiUrl } from '@/env';
import { IUserProfile, IUserProfileUpdate, IUserProfileCreate } from './interfaces';
function authHeaders(token: string) {
return {
headers: {
Authorization: `Bearer ${token}`,
},
};
}
export const api = {
async logInGetToken(username: string, password: string) {
const params = new URLSearchParams();
params.append('username', username);
params.append('password', password);
return axios.post(`${apiUrl}/api/v1/login/access-token`, params);
},
async getMe(token: string) {
return axios.get<IUserProfile>(`${apiUrl}/api/v1/users/me`, authHeaders(token));
},
async updateMe(token: string, data: IUserProfileUpdate) {
return axios.put<IUserProfile>(`${apiUrl}/api/v1/users/me`, data, authHeaders(token));
},
async getUsers(token: string) {
return axios.get<IUserProfile[]>(`${apiUrl}/api/v1/users/`, authHeaders(token));
},
async updateUser(token: string, name: string, data: IUserProfileUpdate) {
return axios.put(`${apiUrl}/api/v1/users/${name}`, data, authHeaders(token));
},
async createUser(token: string, data: IUserProfileCreate) {
return axios.post(`${apiUrl}/api/v1/users/`, data, authHeaders(token));
},
async getRoles(token: string) {
return axios.get(`${apiUrl}/api/v1/roles/`, authHeaders(token));
},
async passwordRecovery(username: string) {
return axios.post(`${apiUrl}/api/v1/password-recovery/${username}`);
},
async resetPassword(password: string, token: string) {
return axios.post(`${apiUrl}/api/v1/reset-password/`, {
new_password: password,
token,
});
},
};