import axios from 'axios' import { getBearerToken } from '@/helpers' const BASE_URI = import.meta.env.VITE_API_URI const publicApi = axios.create() const privateApi = axios.create() const multipartOptions = { headers: { 'Content-Type': 'multipart/form-data' } } privateApi.interceptors.request.use((config) => { config.headers.common['Authorization'] = getBearerToken() return config }, (err) => Promise.reject(err)) export const auth = { async login(data) { return publicApi.post(`${BASE_URI}/auth/login`, data).then(response => response.data) }, async register(data) { return publicApi.post(`${BASE_URI}/auth/register`, data).then(response => response.data) }, async resetPassword(data) { return publicApi.post(`${BASE_URI}/auth/reset-password`, data).then(response => response.data) }, async updatePassword(token, data) { return publicApi.post(`${BASE_URI}/auth/update-password/${token}`, data).then(response => response.data) } } export const apartments = { async create(data) { return privateApi.post(`${BASE_URI}/api/v1/apartments`, data).then(response => response.data) }, async findAll() { return privateApi.get(`${BASE_URI}/api/v1/apartments`).then(response => response.data) }, async findFile(id) { return privateApi.get(`${BASE_URI}/api/v1/apartments/${id}/files`, { responseType: 'blob' }).then(response => response.data) }, async findOne(id) { return privateApi.get(`${BASE_URI}/api/v1/apartments/${id}`).then(response => response.data) }, async update(id, data) { return privateApi.put(`${BASE_URI}/api/v1/apartments/${id}`, data).then(response => response.data) }, async updateHeating(id, data) { return privateApi.put(`${BASE_URI}/api/v1/apartments/${id}/heating`, data).then(response => response.data) }, async updateWindows(id, data) { return privateApi.put(`${BASE_URI}/api/v1/apartments/${id}/windows`, data).then(response => response.data) }, async uploadFile(id, data) { return privateApi.put(`${BASE_URI}/api/v1/apartments/${id}/files`, data, multipartOptions).then(response => response.data) } } export const buildings = { async create(data) { return privateApi.post(`${BASE_URI}/api/v1/buildings`, data).then(response => response.data) }, async findAll() { return privateApi.get(`${BASE_URI}/api/v1/buildings`).then(response => response.data) }, async findOne(id) { return privateApi.get(`${BASE_URI}/api/v1/buildings/${id}`).then(response => response.data) }, async update(id, data) { return privateApi.put(`${BASE_URI}/api/v1/buildings/${id}`, data).then(response => response.data) }, async updateBasement(id, data) { return privateApi.put(`${BASE_URI}/api/v1/buildings/${id}/basement`, data).then(response => response.data) }, async updateCharacteristics(id, data) { return privateApi.put(`${BASE_URI}/api/v1/buildings/${id}/characteristics`, data).then(response => response.data) }, async updateFacade(id, data) { return privateApi.put(`${BASE_URI}/api/v1/buildings/${id}/facade`, data).then(response => response.data) }, async updateHeating(id, data) { return privateApi.put(`${BASE_URI}/api/v1/buildings/${id}/heating`, data).then(response => response.data) }, async updateRoof(id, data) { return privateApi.put(`${BASE_URI}/api/v1/buildings/${id}/roof`, data).then(response => response.data) } } export const self = { async findOne() { return privateApi.get(`${BASE_URI}/api/v1/self`).then(response => response.data) } } export const users = { async findAll() { return privateApi.get(`${BASE_URI}/api/v1/users`).then(response => response.data) }, async findOne(id) { return privateApi.get(`${BASE_URI}/api/v1/users/${id}`).then(response => response.data) }, async update(id, data) { return privateApi.put(`${BASE_URI}/api/v1/users/${id}`, data).then(response => response.data) }, async updatePassword(id, data) { return privateApi.put(`${BASE_URI}/api/v1/users/${id}/change-password`, data).then(response => response.data) }, async updateSharing(id, data) { return privateApi.put(`${BASE_URI}/api/v1/users/${id}/sharing`, data).then(response => response.data) } }