🎉 First commit, from couchbase generator, basic changes
not tested / updated yet
This commit is contained in:
48
{{cookiecutter.project_slug}}/frontend/src/api.ts
Normal file
48
{{cookiecutter.project_slug}}/frontend/src/api.ts
Normal 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,
|
||||
});
|
||||
},
|
||||
};
|
Reference in New Issue
Block a user