monkeytype/backend/dao/public-stats.js

33 lines
714 B
JavaScript
Raw Normal View History

2021-06-12 20:39:30 +08:00
const MonkeyError = require("../handlers/error");
const { mongoDB } = require("../init/mongodb");
const { roundTo2 } = require("../handlers/misc");
class PublicStatsDAO {
static async increment(started, completed, time){
time = roundTo2(time);
await mongoDB()
.collection("users")
.updateOne(
{ name: 'startedTests' },
{ $inc: { value: started } }
);
await mongoDB()
.collection("users")
.updateOne(
{ name: 'completedTests' },
{ $inc: { value: completed } }
);
await mongoDB()
.collection("users")
.updateOne(
{ name: 'timeTyping' },
{ $inc: { value: time } }
);
return true;
}
}
module.exports = PublicStatsDAO;