Switch username update to one query

This commit is contained in:
Ajay Ramachandran 2021-06-28 22:05:15 -04:00
parent 8b54e965a2
commit 6f18a49ba0

View file

@ -69,8 +69,7 @@ export async function setUsername(req: Request, res: Response) {
if (row.userName && row.userName.length !== 0) {
//already exists, update this row
oldUserName = row.userName;
await db.prepare('run', `UPDATE "userNames" SET "userName" = ? WHERE "userID" = ?`, [userName, userID]);
await db.prepare('run', `UPDATE "userNames" SET "locked" = ? WHERE "userID" = ?`, [locked, userID]);
await db.prepare('run', `UPDATE "userNames" SET "userName" = ?, "locked" = ? WHERE "userID" = ?`, [userName, locked, userID]);
} else {
//add to the db
await db.prepare('run', `INSERT INTO "userNames"("userID", "userName", "locked") VALUES(?, ?, ?)`, [userID, userName, locked]);