XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

SpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 1 Star 0
返回提交历史

XFEstudio/SpaceNinjaServer

chore: simplify logoutController (#1342)

Reducing 3-4 MongoDB operations to only 1. Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/1342 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>

fd93f345
Sainan <63328889+Sainan@users.noreply.github.com>
提交于

代码差异

1 个文件 +18 -9
Modified src/controllers/api/logoutController.ts +18 -9
@@ -1,19 +1,28 @@
1 1 import { RequestHandler } from "express";
2 import { getAccountIdForRequest } from "@/src/services/loginService";
3 2 import { Account } from "@/src/models/loginModel";
4 3
5 const logoutController: RequestHandler = async (req, res) => {
6 const accountId = await getAccountIdForRequest(req);
7 const account = await Account.findById(accountId);
8 if (account) {
9 account.Nonce = 0;
10 await account.save();
4 export const logoutController: RequestHandler = async (req, res) => {
5 if (!req.query.accountId) {
6 throw new Error("Request is missing accountId parameter");
11 7 }
8 const nonce: number = parseInt(req.query.nonce as string);
9 if (!nonce) {
10 throw new Error("Request is missing nonce parameter");
11 }
12
13 await Account.updateOne(
14 {
15 _id: req.query.accountId,
16 Nonce: nonce
17 },
18 {
19 Nonce: 0
20 }
21 );
22
12 23 res.writeHead(200, {
13 24 "Content-Type": "text/html",
14 25 "Content-Length": 1
15 26 });
16 27 res.end("1");
17 28 };
18
19 export { logoutController };