Skip to content
Snippets Groups Projects
Commit 1daeaea6 authored by LAFORÊT Nicolas's avatar LAFORÊT Nicolas :rabbit2:
Browse files

:clown: mock back data & :recycle:️ refactor money api calls

parent 4148cb07
Branches
1 merge request!7🔀 V1
import axios from 'axios';
import { Product } from '../cart/CartTypes';
import { mockedStocks } from './mocks';
const BASE_URL = "https://" + process.env.REACT_APP_BACK_URL + "/api/v1";
const APIKEY = process.env.REACT_APP_BACK_API_KEY || 'theapikey'
// Fetch items from API
export async function getItems(): Promise<Product[]> {
// Fetch stocks
// Fetch stocks data
const stocks: any[] = await axios.get(`${BASE_URL}/stock`, {
headers: {
'Content-Type': 'application/json',
......@@ -15,10 +16,10 @@ export async function getItems(): Promise<Product[]> {
}).then(({ data }) => data)
.catch(error => {
console.error(error);
return [];
return mockedStocks;
});
// Format products
// Format products data
const products = stocks.map(stock => new Product({
name: stock.item.name,
category: stock.item.category.name,
......
export const mockedStocks: any[] = [
{
quantity: 36,
item: {
name: "Coca-Cola",
price: 0.5,
subscriber_price: 0.5,
category: {
name: "Boisson"
}
}
},
{
quantity: 24,
item: {
name: "Fanta",
price: 0.5,
subscriber_price: 0.5,
category: {
name: "Boisson"
}
}
},
{
quantity: 50,
item: {
name: "Ice-tea",
price: 0.5,
subscriber_price: 0.5,
category: {
name: "Boisson"
}
}
},
{
quantity: 12,
item: {
name: "Bueno",
price: 0.6,
subscriber_price: 0.6,
category: {
name: "Snack"
}
}
},
{
quantity: 31,
item: {
name: "Chips",
price: 0.3,
subscriber_price: 0.3,
category: {
name: "Snack"
}
}
},
{
quantity: 12,
item: {
name: "Twix",
price: 0.5,
subscriber_price: 0.5,
category: {
name: "Snack"
}
}
},
{
quantity: 1000,
item: {
name: "Adhésion",
price: 4,
subscriber_price: 0,
category: {
name: "Divers"
}
}
},
];
......@@ -2,20 +2,21 @@ import axios from 'axios';
const BASE_URL = "https://" + process.env.REACT_APP_MONEY_URL;
// Fetch users from API
export function getTransactions(studentNumber: string): Promise<any> {
return new Promise((resolve, reject) => {
axios.get(`${BASE_URL}/transactions/get/${studentNumber}`, {
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json'
}
}).then(function ({ data }) {
console.log(data);
resolve(data);
}).catch(function (error) {
console.error(error);
reject(error);
// Fetch transactions from API
export async function getTransactions(studentNumber: string): Promise<any> {
// Fetch transactions data
const transactionsData: any[] = await axios.get(`${BASE_URL}/api/etudiants`, {
headers: {
'Content-Type': 'application/json',
}
}).then(({ data }) => data)
.catch(error => {
console.error(error);
return [];
});
});
console.log(transactionsData);
// TODO: Format transaction data
return transactionsData;
}
\ No newline at end of file
......@@ -22,7 +22,7 @@ const BASE_URL = "https://" + process.env.REACT_APP_STUDENT_URL;
// Fetch users from API
export async function getUsers(): Promise<User[]> {
// Fetch users
// Fetch users data
const usersData: any[] = await axios.get(`${BASE_URL}/api/etudiants`, {
headers: {
'Content-Type': 'application/json',
......@@ -33,7 +33,7 @@ export async function getUsers(): Promise<User[]> {
return [];
});
// Format users
// Format users data
const users = usersData.map(user => new User(
user.lastname,
user.firstname,
......
......@@ -29,7 +29,7 @@ const Stock = () => {
let updateProductQuantity = (productId, quantity) => {
let productsTemp = productsList;
let product = productsTemp[productId];
product.quantity = quantity;
product.stock = quantity;
setProductsList([...productsTemp]);
};
......@@ -103,7 +103,7 @@ const Stock = () => {
scope="col"
className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
>
Prix
Prix / Adhérent
</th>
<th
scope="col"
......@@ -121,16 +121,16 @@ const Stock = () => {
<tr key={product.name} className={productIdx % 2 === 0 ? 'bg-white' : 'bg-gray-50'}>
<td className="px-4 py-4 whitespace-nowrap text-sm font-medium text-gray-900">{product.name}</td>
<td className="px-4 py-4 whitespace-nowrap text-sm text-gray-500">{product.category}</td>
<td className="px-4 py-4 whitespace-nowrap text-sm text-gray-500">{product.price}</td>
<td className="px-4 py-4 whitespace-nowrap text-sm text-gray-500">{product.price.toFixed(2)}€ / {product?.subscriberPrice?.toFixed(2) ?? product.price.toFixed(2)}</td>
<td className="px-4 py-4 whitespace-nowrap text-sm text-gray-500">
{product.edit ?
<input
className="shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:max-w-xs sm:text-sm border-gray-300 rounded-md"
onChange={(e) => { updateProductQuantity(productIdx, e.target.value) }}
type="number"
value={product.quantity}
value={product.stock}
/>
: <span>{product.quantity}</span>
: <span>{product.stock}</span>
}
</td>
<td className="pr-4 py-4 whitespace-nowrap text-right text-sm font-medium">
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment