chore: simplify logoutController
Some checks are pending
Build Docker image / docker (push) Waiting to run
Build / build (18) (push) Successful in 1m15s
Build / build (20) (push) Successful in 1m5s
Build / build (22) (push) Successful in 1m12s
Build / build (18) (pull_request) Successful in 1m19s
Build / build (22) (pull_request) Successful in 52s
Build / build (20) (pull_request) Successful in 1m15s

Reducing 3-4 MongoDB operations to only 1.
This commit is contained in:
Sainan 2025-03-27 02:05:34 +01:00
parent 5f9475f750
commit 57f6f37e85

View File

@ -1,19 +1,24 @@
import { RequestHandler } from "express"; import { RequestHandler } from "express";
import { getAccountIdForRequest } from "@/src/services/loginService";
import { Account } from "@/src/models/loginModel"; import { Account } from "@/src/models/loginModel";
const logoutController: RequestHandler = async (req, res) => { export const logoutController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req); if (!req.query.accountId) {
const account = await Account.findById(accountId); throw new Error("Request is missing accountId parameter");
if (account) { }
account.Nonce = 0; const nonce: number = parseInt(req.query.nonce as string);
await account.save(); if (!nonce) {
throw new Error("Request is missing nonce parameter");
} }
res.writeHead(200, {
"Content-Type": "text/html",
"Content-Length": 1
});
res.end("1");
};
export { logoutController }; await Account.updateOne(
{
_id: req.query.accountId,
Nonce: nonce
},
{
Nonce: 0
}
);
res.end();
};