mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-02-05 13:27:49 +08:00
33 lines
819 B
JavaScript
33 lines
819 B
JavaScript
|
const MonkeyError = require("../handlers/error");
|
||
|
const { mongoDB } = require("../init/mongodb");
|
||
|
|
||
|
class QuoteRatingsDAO {
|
||
|
static async submit(quoteId, language, rating, update) {
|
||
|
if (update) {
|
||
|
return await mongoDB()
|
||
|
.collection("quote-rating")
|
||
|
.updateOne(
|
||
|
{ quoteId, language },
|
||
|
{ $inc: { totalRating: rating } },
|
||
|
{ upsert: true }
|
||
|
);
|
||
|
} else {
|
||
|
return await mongoDB()
|
||
|
.collection("quote-rating")
|
||
|
.updateOne(
|
||
|
{ quoteId, language },
|
||
|
{ $inc: { ratings: 1, totalRating: rating } },
|
||
|
{ upsert: true }
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static async get(quoteId, language) {
|
||
|
return await mongoDB()
|
||
|
.collection("quote-rating")
|
||
|
.findOne({ quoteId, language });
|
||
|
}
|
||
|
}
|
||
|
|
||
|
module.exports = QuoteRatingsDAO;
|