This commit is contained in:
@@ -17,29 +17,37 @@ const app = express()
|
||||
app.use(morgan('combined'))
|
||||
app.use(bodyParser.json())
|
||||
app.use(cors())
|
||||
app.get('/database', (req, res) => {
|
||||
const promise = databases.listDocuments('lifetracker-db', 'ryan');
|
||||
promise.then(function ({ documents } = response) {
|
||||
|
||||
// app.get('/database', (req, res) => {
|
||||
// const promise = databases.listDocuments('lifetracker-db', 'ryan');
|
||||
// promise.then(function ({ documents } = response) {
|
||||
|
||||
|
||||
res.send(documents)
|
||||
}, function (error) {
|
||||
console.log(error);
|
||||
});
|
||||
})
|
||||
// res.send(documents)
|
||||
// }, function (error) {
|
||||
// console.log(error);
|
||||
// });
|
||||
// })
|
||||
|
||||
app.get('/entry/:date', (req, res) => {
|
||||
var date = new Date(req.params['date']).toISOString().replace(/T.*/,"");
|
||||
console.log("Fetching entry for " + date);
|
||||
// app.get('/entry/:date', (req, res) => {
|
||||
// var date = new Date(req.params['date']).toISOString().replace(/T.*/,"");
|
||||
// console.log("Fetching entry for " + date);
|
||||
|
||||
const promise = databases.listDocuments('lifetracker-db', 'ryan');
|
||||
promise.then(function ({ documents } = response) {
|
||||
// const promise = databases.listDocuments('lifetracker-db', 'ryan');
|
||||
// promise.then(function ({ documents } = response) {
|
||||
|
||||
entries = documents.map(e => e.Date)
|
||||
res.send(entries)
|
||||
}, function (error) {
|
||||
console.log(error);
|
||||
});
|
||||
})
|
||||
// entries = documents.map(e => e.Date)
|
||||
// res.send(entries)
|
||||
// }, function (error) {
|
||||
// console.log(error);
|
||||
// });
|
||||
// })
|
||||
|
||||
const path = __dirname + '/dist/'
|
||||
|
||||
app.use(express.static(path))
|
||||
|
||||
app.get(/.*/, function (req,res) {
|
||||
res.sendFile(path + "index.html");
|
||||
});
|
||||
app.listen(process.env.PORT || 8081)
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+15
@@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Life Tracker Expanded</title>
|
||||
<script type="module" crossorigin src="/assets/index-64281767.js"></script>
|
||||
<link rel="stylesheet" href="/assets/index-b41ae507.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -8,38 +8,43 @@ const client = new sdk.Client();
|
||||
|
||||
const databases = new sdk.Databases(client);
|
||||
|
||||
function importCSV(){
|
||||
console.log("Worked.");
|
||||
}
|
||||
|
||||
var data = fs.readFileSync('data.csv')
|
||||
.toString() // convert Buffer to string
|
||||
.split('\n') // split string to lines
|
||||
.slice(1) // remove first line
|
||||
.map(e => e.trim()) // remove white spaces for each line
|
||||
.map(e => {
|
||||
var entry = e.split(','); // split each line to array
|
||||
var date = strftime("%Y-%m-%d", new Date("2023/" + entry[0]));
|
||||
var hours = entry.slice(2, 26).map(h => parseFloat(h));
|
||||
var mood = parseInt(entry[26]);
|
||||
var comments = entry.slice(27).filter(x => x != "").join().replace(/^"/,"").replace(/"$/,'')
|
||||
|
||||
var dbEntry = {
|
||||
date: date,
|
||||
hours: hours,
|
||||
mood: mood,
|
||||
comments: comments
|
||||
};
|
||||
client
|
||||
.setEndpoint('http://ryanpandya.com:8080/v1') // Your API Endpoint
|
||||
.setProject('lifetracker') // Your project ID
|
||||
.setKey('015d60dd9dc8fb1b34b9f66459a27b3aded55c93a5b551d78be7a48b94f26e1781020a65407116265e3d93fac9d99e717b676c158bdda351aae22877da8f8b14af4d310d8fe3d4e3005adcc0f228b95f7efae308e638610bd97f9d44e8c322c07f38f9ba17a264efb65d3601c5302c2a5072cd294e69d9baacd19ba9ec9a117f') // Your secret API key
|
||||
|
||||
const promise = databases.createDocument('lifetracker-db', 'ryan', date, dbEntry);
|
||||
|
||||
promise.then(function (response) {
|
||||
console.log(response);
|
||||
return (response);
|
||||
}, function (error) {
|
||||
console.log(error);
|
||||
});
|
||||
})
|
||||
function importsCSV(){
|
||||
var data = fs.readFileSync('data.csv')
|
||||
.toString() // convert Buffer to string
|
||||
.split('\n') // split string to lines
|
||||
.slice(1) // remove first line
|
||||
.map(e => e.trim()) // remove white spaces for each line
|
||||
.map(e => {
|
||||
var entry = e.split(','); // split each line to array
|
||||
var date = strftime("%Y-%m-%d", new Date("2023/" + entry[0]));
|
||||
var hours = entry.slice(2, 26).map(h => parseFloat(h));
|
||||
var mood = parseInt(entry[26]);
|
||||
var comments = entry.slice(27).filter(x => x != "").join().replace(/^"/,"").replace(/"$/,'')
|
||||
|
||||
var dbEntry = {
|
||||
date: date,
|
||||
hours: hours,
|
||||
mood: mood,
|
||||
comments: comments
|
||||
};
|
||||
client
|
||||
.setEndpoint('http://ryanpandya.com:8080/v1') // Your API Endpoint
|
||||
.setProject('lifetracker') // Your project ID
|
||||
.setKey('015d60dd9dc8fb1b34b9f66459a27b3aded55c93a5b551d78be7a48b94f26e1781020a65407116265e3d93fac9d99e717b676c158bdda351aae22877da8f8b14af4d310d8fe3d4e3005adcc0f228b95f7efae308e638610bd97f9d44e8c322c07f38f9ba17a264efb65d3601c5302c2a5072cd294e69d9baacd19ba9ec9a117f') // Your secret API key
|
||||
|
||||
const promise = databases.createDocument('lifetracker-db', 'ryan', date, dbEntry);
|
||||
|
||||
promise.then(function (response) {
|
||||
console.log(response);
|
||||
return (response);
|
||||
}, function (error) {
|
||||
console.log(error);
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
exports.entries = data;
|
||||
exports.entries = importCSV;
|
||||
Reference in New Issue
Block a user