import express from 'express'; import logger from 'morgan'; import multer from 'multer'; import neatCsv from 'neat-csv' import sortTransactions from './sortTransactions.js' import path from 'path'; import {fileURLToPath} from 'node:url'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const app = express() const port = 3000 app.use(express.json()) app.use(logger('dev')) const storage = multer.memoryStorage() const upload = multer({ storage: storage }) app.get('/api/hello', (req, res) => { res.send( `

Hello Big World

` ) }) app.post('/api/upload/', upload.single('file'), async (req, res) => { console.log() if(process.env.DEMO == "true"){ res.send(tempTransactions) console.log("Hit") return } if(!req.file) { res.send('No file uploaded.') return } const csvString = req.file.buffer.toString('utf8') let results = await sortTransactions(csvString, ['Bills', 'Groceries', 'Restaurants', 'Entertainment', 'Shopping', 'Travel'] ) let transactions = await neatCsv(results) // res.send(transactions) }) app.use('/', express.static(path.join(__dirname, 'public'))) app.listen(port, () => { console.log(`Example app listening on port ${port}`) }) var tempTransactions = [ { "Status": "Cleared", "Date": "02/03/2023", "Description": "CRUNCHYROLL", "Debit": "11.03", "Credit": "", "Category": "Entertainment" }, { "Status": "Cleared", "Date": "02/01/2023", "Description": "GOOGLE CLOUD", "Debit": "0.03", "Credit": "", "Category": "Bills" }, { "Status": "Cleared", "Date": "01/30/2023", "Description": "FAMILY CH", "Debit": "50.00", "Credit": "", "Category": "Bills" }, { "Status": "Cleared", "Date": "01/30/2023", "Description": "PUD", "Debit": "89.05", "Credit": "", "Category": "Bills" }, { "Status": "Cleared", "Date": "01/24/2023", "Description": "TARGET.COM", "Debit": "5.00", "Credit": "", "Category": "Shopping" }, { "Status": "Cleared", "Date": "01/24/2023", "Description": "TARGET.COM", "Debit": "25.57", "Credit": "", "Category": "Shopping" }, { "Status": "Cleared", "Date": "01/24/2023", "Description": "Amazon.com", "Debit": "5.62", "Credit": "", "Category": "Shopping" }, { "Status": "Cleared", "Date": "01/24/2023", "Description": "TARGET", "Debit": "8.43", "Credit": "", "Category": "Shopping" }, { "Status": "Cleared", "Date": "01/22/2023", "Description": "GOOGLE YouTubePremium", "Debit": "16.57", "Credit": "", "Category": "Entertainment" }, { "Status": "Cleared", "Date": "01/20/2023", "Description": "PEROT MUSEUM CAFE QPS DALLAS TX", "Debit": "25.82", "Credit": "", "Category": "Restaurants" }, { "Status": "Cleared", "Date": "01/20/2023", "Description": "THE HOME DEPOT", "Debit": "19.14", "Credit": "", "Category": "Groceries" }, { "Status": "Cleared", "Date": "01/20/2023", "Description": "Amazon.com", "Debit": "13.12", "Credit": "", "Category": "Shopping" }, { "Status": "Cleared", "Date": "01/20/2023", "Description": "AMZN Mktp", "Debit": "6.55", "Credit": "", "Category": "Shopping" }, { "Status": "Cleared", "Date": "01/19/2023", "Description": "STARBUCKS STORE", "Debit": "10.28", "Credit": "", "Category": "Restaurants" }, { "Status": "Cleared", "Date": "01/19/2023", "Description": "TARGET.COM", "Debit": "52.74", "Credit": "", "Category": "Shopping" }, { "Status": "Cleared", "Date": "01/19/2023", "Description": "ZIPLY FIBER", "Debit": "50.94", "Credit": "", "Category": "Bills" }, { "Status": "Cleared", "Date": "01/18/2023", "Description": "7-ELEVEN 39782 DFW AIRPORT TX", "Debit": "1.72", "Credit": "", "Category": "Travel" }, { "Status": "Cleared", "Date": "01/18/2023", "Description": "BUC-EE'S #36 TERRELL TX", "Debit": "21.53", "Credit": "", "Category": "Travel" }, { "Status": "Cleared", "Date": "01/17/2023", "Description": "DALLAS ZOO MANAGEMENT DALLAS TX", "Debit": "40.00", "Credit": "", "Category": "Entertainment" } ]