mirror of
https://github.com/gnmyt/myspeed.git
synced 2026-01-08 22:19:46 -06:00
22 lines
774 B
JavaScript
22 lines
774 B
JavaScript
const recommendations = require('../models/Recommendations');
|
|
const {triggerEvent} = require("./integrations");
|
|
|
|
module.exports.getCurrent = async () => {
|
|
return await recommendations.findOne();
|
|
}
|
|
|
|
module.exports.update = async (ping, download, upload) => {
|
|
const configuration = {ping: Math.round(ping), download: parseFloat(download.toFixed(2)),
|
|
upload: parseFloat(upload.toFixed(2))};
|
|
|
|
const existing = await recommendations.findOne();
|
|
|
|
triggerEvent("recommendationsUpdated", configuration).then(() => {});
|
|
|
|
if (existing) {
|
|
await recommendations.update(configuration, {where: {id: existing.id}});
|
|
return recommendations.findOne({where: {id: existing.id}});
|
|
}
|
|
|
|
return recommendations.create(configuration);
|
|
} |