Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions inventory-manager/src/services/Requests.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import axios, {type AxiosResponse} from "axios";
import type {Product, ProductResponse} from "../types/Product";

const BASE_URL = "http://localhost:9090";

export const getProducts = async (filters?: {
name?: string;
category?: string[];
Expand All @@ -15,18 +13,18 @@ export const getProducts = async (filters?: {
sortBy?: string;
sortDir?: "asc" | "desc";
}): Promise<ProductResponse> => {
const response = await axios.get(`${BASE_URL}/products`, {
const response = await axios.get(`/api/products`, {
params: filters,
});
return response.data;
};

export const getCategories = async (): Promise<AxiosResponse<any, any>> => {
return await axios.get(`${BASE_URL}/products/categories`);
return await axios.get(`/api/products/categories`);
};

export const getSummary = async (): Promise<AxiosResponse<any, any>> => {
return await axios.get(`${BASE_URL}/products/summary`);
return await axios.get(`/api/products/summary`);
};

export const getFilteredProducts = async (params?: {
Expand All @@ -42,7 +40,7 @@ export const getFilteredProducts = async (params?: {
sortBy?: string;
sortDir?: "asc" | "desc";
}): Promise<AxiosResponse<any, any>> => {
return await axios.get(`${BASE_URL}/products/filters`, {
return await axios.get(`/api/products/filters`, {
params,
paramsSerializer: (params) => {
const query = new URLSearchParams();
Expand All @@ -59,23 +57,23 @@ export const getFilteredProducts = async (params?: {
};

export const createProduct = async (product: Omit<Product, "id" | "createdAt" | "updatedAt">): Promise<Product> => {
const response = await axios.post(`${BASE_URL}/products`, product);
const response = await axios.post(`/api/products`, product);
return response.data;
};

export const updateProduct = async (id: string, product: Partial<Product>): Promise<Product> => {
const response = await axios.put(`${BASE_URL}/products/${id}`, product);
const response = await axios.put(`/api/products/${id}`, product);
return response.data;
};

export const markOutOfStock = async (id: string): Promise<void> => {
await axios.patch(`${BASE_URL}/products/${id}/outofstock`);
await axios.patch(`/api/products/${id}/outofstock`);
};

export const markInStock = async (id: string): Promise<void> => {
await axios.patch(`${BASE_URL}/products/${id}/instock`);
await axios.patch(`/api/products/${id}/instock`);
};

export const deleteProduct = async (id: string): Promise<void> => {
await axios.delete(`${BASE_URL}/products/${id}`);
await axios.delete(`/api/products/${id}`);
};
14 changes: 13 additions & 1 deletion inventory-manager/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
/// <reference types="vitest" />
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vite.dev/config/
export default defineConfig({
plugins: [react()],
})
server: {
host: true,
port: 8080,
proxy: {
'/api': {
target: 'http://localhost:9090',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ''),
},
},
},
})