mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2024-11-10 17:04:49 +08:00
added protection against duplicate user docs
This commit is contained in:
parent
3d57ad2ec9
commit
7e682136f7
1 changed files with 4 additions and 1 deletions
|
@ -6,6 +6,9 @@ const { updateAuthEmail } = require("../handlers/auth");
|
|||
|
||||
class UsersDAO {
|
||||
static async addUser(name, email, uid) {
|
||||
const user = await mongoDB().collection("users").findOne({ uid });
|
||||
if (user)
|
||||
throw new MonkeyError(400, "User document already exists", "addUser");
|
||||
return await mongoDB()
|
||||
.collection("users")
|
||||
.insertOne({ name, email, uid, addedAt: Date.now() });
|
||||
|
@ -64,7 +67,7 @@ class UsersDAO {
|
|||
|
||||
static async getUser(uid) {
|
||||
const user = await mongoDB().collection("users").findOne({ uid });
|
||||
if (!user) throw new MonkeyError(404, "User not found", "get user");
|
||||
if (user) throw new MonkeyError(404, "User not found", "get user");
|
||||
return user;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue