diff --git a/lifetracker-server/src/app.js b/lifetracker-server/src/app.js index 893da8f..a1f54ed 100644 --- a/lifetracker-server/src/app.js +++ b/lifetracker-server/src/app.js @@ -28,7 +28,7 @@ app.get('/database', (req, res) => { }) app.get('/entry/:date', (req, res) => { - var date = strftime("%x", new Date(req.params['date']) ); + var date = new Date(req.params['date']).toISOString().replace(/T.*/,""); console.log("Fetching entry for " + date); const promise = databases.listDocuments('lifetracker-db', 'ryan'); diff --git a/lifetracker-vue/src/services/appwrite.js b/lifetracker-vue/src/services/appwrite.js new file mode 100644 index 0000000..6ed4e9d --- /dev/null +++ b/lifetracker-vue/src/services/appwrite.js @@ -0,0 +1,52 @@ +import { Client, Databases, Account } from "appwrite"; + +class AppwriteService { + databaseId = 'lifetracker-db'; + collectionId = "ryan"; + constructor() { + this.appwrite = new Client().setEndpoint("http://ryanpandya.com:8080/v1").setProject("lifetracker") + this.database = new Databases(this.appwrite); + this.account = new Account(this.appwrite); + } + + subscribe = (callback) => { + return this.appwrite.subscribe('databases.lifetracker-db.collections.ryan.documents', callback); + // "databases.${this.databaseId}.collections.${this.collectionId}.documents", callback); + } + + addEntry = async ({ date, hours, mood, comments }) => { + await this.database.createDocument(this.databaseId, this.collectionId, + date, + { date: new Date(date), hours: hours, mood: mood, comments: comments }); + } + + deleteEntry = async (entryId) => { + await this.database.deleteDocument(this.databaseId, this.collectionId, entryId); + } + + updateEntry = async ({ date, hours, mood, comments }) => { + var hours = JSON.parse("[" + hours + "]") + await this.database.updateDocument(this.databaseId, this.collectionId, + date, + { date: new Date(date), hours: hours, mood: mood, comments: comments }); + } + + getUser = async () => { + return await this.account.get(); + } + + login = async () => { + await this.account.createAnonymousSession(); + return await this.getUser(); + } + + getEntries = async () => { + return (await this.database.listDocuments(this.databaseId, this.collectionId)).documents; + } + + logout = () => { + return this.appwrite.account.deleteSession('current'); + } +} + +export default new AppwriteService() \ No newline at end of file diff --git a/lifetracker-vue/src/views/DatabaseView.vue b/lifetracker-vue/src/views/DatabaseView.vue index 07ccd5d..432514b 100644 --- a/lifetracker-vue/src/views/DatabaseView.vue +++ b/lifetracker-vue/src/views/DatabaseView.vue @@ -1,23 +1,61 @@