mirror of
https://github.com/gnmyt/myspeed.git
synced 2026-01-07 05:29:39 -06:00
Updated the recommendations controller
This commit is contained in:
@@ -1,17 +1,12 @@
|
||||
const db = require('../index').database;
|
||||
const recommendations = require('../models/Recommendations');
|
||||
|
||||
// Gets the current recommendations
|
||||
module.exports.get = () => {
|
||||
return db.prepare("SELECT * FROM recommendations").get();
|
||||
module.exports.get = async () => {
|
||||
return await recommendations.findOne();
|
||||
}
|
||||
|
||||
// Sets new recommendations
|
||||
module.exports.set = (ping, download, upload) => {
|
||||
if (this.get() === undefined) {
|
||||
return db.prepare("INSERT INTO recommendations (ping, download, upload) VALUES (?, ?, ?)")
|
||||
.run(Math.round(ping), download.toFixed(2), upload.toFixed(2));
|
||||
} else {
|
||||
return db.prepare("UPDATE recommendations SET ping = ?, download = ?, upload = ?")
|
||||
.run(Math.round(ping), download.toFixed(2), upload.toFixed(2));
|
||||
}
|
||||
module.exports.set = async (ping, download, upload) => {
|
||||
await recommendations.destroy({truncate: true});
|
||||
return await recommendations.create({ping: Math.round(ping), download: download.toFixed(2), upload: upload.toFixed(2)});
|
||||
}
|
||||
Reference in New Issue
Block a user