/
3.0-created_app_data
3.0-created_app_data
Now we are starting to think about the application data
This clever bit of code can generate code on the fly using json-server. Install json-server with the command npm install -g json-server
// index.js
module.exports = () => {
const sales = {sale: [] }
// Create 10 sales @VAT rate 20%
let i = 0;
for (; i < 10; i++) {
let salePrice = Math.floor(Math.random() * 50) + 50;
let totalPrice = (salePrice * 1.20).toFixed(2);
let vatToPay = (totalPrice - salePrice).toFixed(2);
sales.sale.push({ id: i, salePrice : `${salePrice}`, totalPrice: `${totalPrice}`, vatToPay: `${vatToPay}`, vatRate: 20.00})
}
// Create 10 sales @VAT rate 15%
for (; i < 20; i++) {
let salePrice = Math.floor(Math.random() * 50) + 100;
let totalPrice = (salePrice * 1.15).toFixed(2);
let vatToPay = (totalPrice - salePrice).toFixed(2);
sales.sale.push({ id: i, salePrice : `${salePrice}`, totalPrice: `${totalPrice}`, vatToPay: `${vatToPay}`, vatRate: 15.00 })
}
return sales
}