mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-10-09 23:25:53 +08:00
got public stats to work
This commit is contained in:
parent
d4ad8afacd
commit
0cf495e127
2 changed files with 16 additions and 10 deletions
|
@ -1,6 +1,6 @@
|
|||
const ResultDAO = require("../../dao/result");
|
||||
const UserDAO = require("../../dao/user");
|
||||
// const PublicStatsDAO = require("../../dao/public-stats");
|
||||
const PublicStatsDAO = require("../../dao/public-stats");
|
||||
const {
|
||||
validateObjectValues,
|
||||
validateResult,
|
||||
|
@ -168,6 +168,8 @@ class ResultController {
|
|||
|
||||
await UserDAO.updateTypingStats(uid, result.restartCount, tt);
|
||||
|
||||
await PublicStatsDAO.updateStats(result.restartCount, tt);
|
||||
|
||||
let addedResult = await ResultDAO.addResult(uid, result);
|
||||
|
||||
return res.status(200).json({
|
||||
|
|
|
@ -4,17 +4,21 @@ const { roundTo2 } = require("../handlers/misc");
|
|||
|
||||
class PublicStatsDAO {
|
||||
//needs to be rewritten, this is public stats not user stats
|
||||
static async increment(started, completed, time) {
|
||||
static async updateStats(restartCount, 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 } });
|
||||
.collection("public")
|
||||
.updateOne(
|
||||
{ type: "stats" },
|
||||
{
|
||||
$inc: {
|
||||
testsCompleted: 1,
|
||||
testsStarted: restartCount + 1,
|
||||
timeTyping: time,
|
||||
},
|
||||
},
|
||||
{ upsert: true }
|
||||
);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue