From 0c64342b2cfa3c7d68fb31ee1473d36393d68222 Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Wed, 6 Apr 2022 21:10:50 +0200 Subject: [PATCH] Created the speedtest controller --- server/controller/speedtests.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 server/controller/speedtests.js diff --git a/server/controller/speedtests.js b/server/controller/speedtests.js new file mode 100644 index 00000000..16b0709d --- /dev/null +++ b/server/controller/speedtests.js @@ -0,0 +1,28 @@ +const db = require('../index').database; + +// Inserts a new speedtest into the database +module.exports.create = (ping, download, upload) => { + return db.prepare("INSERT INTO speedtests (ping, download, upload) VALUES (?, ?, ?)").run(ping, download, upload).lastInsertRowid; +} + +// Gets a specific speedtest by id +module.exports.get = (id) => { + return db.prepare("SELECT * FROM speedtests WHERE id = ?").get(id); +} + +// Lists all speedtests from the database +module.exports.list = () => { + return db.prepare("SELECT * FROM speedtests").all(); +} + +// Gets the latest speedtest from the database +module.exports.latest = () => { + return db.prepare("SELECT * FROM speedtests ORDER BY id DESC").get(); +} + +// Deletes a specific speedtest +module.exports.delete = (id) => { + if (this.get(id) === undefined) return undefined; + db.prepare("DELETE FROM speedtests WHERE id = ?").run(id); + return true; +} \ No newline at end of file