chore(webui): remove administratorNames entry when deleting account
All checks were successful
Build / build (pull_request) Successful in 4m8s

This commit is contained in:
Sainan 2025-09-27 19:44:09 +02:00
parent 17e1eb86dd
commit e67fac591b

View File

@ -1,5 +1,5 @@
import type { RequestHandler } from "express"; import type { RequestHandler } from "express";
import { getAccountIdForRequest } from "../../services/loginService.ts"; import { getAccountForRequest } from "../../services/loginService.ts";
import { Account, Ignore } from "../../models/loginModel.ts"; import { Account, Ignore } from "../../models/loginModel.ts";
import { Inbox } from "../../models/inboxModel.ts"; import { Inbox } from "../../models/inboxModel.ts";
import { Inventory } from "../../models/inventoryModels/inventoryModel.ts"; import { Inventory } from "../../models/inventoryModels/inventoryModel.ts";
@ -12,33 +12,44 @@ import { Leaderboard } from "../../models/leaderboardModel.ts";
import { deleteGuild } from "../../services/guildService.ts"; import { deleteGuild } from "../../services/guildService.ts";
import { Friendship } from "../../models/friendModel.ts"; import { Friendship } from "../../models/friendModel.ts";
import { sendWsBroadcastTo } from "../../services/wsService.ts"; import { sendWsBroadcastTo } from "../../services/wsService.ts";
import { config } from "../../services/configService.ts";
import { saveConfig } from "../../services/configWriterService.ts";
export const deleteAccountController: RequestHandler = async (req, res) => { export const deleteAccountController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req); const account = await getAccountForRequest(req);
// If this account is an admin, remove it from administratorNames
if (config.administratorNames) {
const adminIndex = config.administratorNames.indexOf(account.DisplayName);
if (adminIndex != -1) {
config.administratorNames.splice(adminIndex, 1);
await saveConfig();
}
}
// If account is the founding warlord of a guild, delete that guild as well. // If account is the founding warlord of a guild, delete that guild as well.
const guildMember = await GuildMember.findOne({ accountId, rank: 0, status: 0 }); const guildMember = await GuildMember.findOne({ accountId: account._id, rank: 0, status: 0 });
if (guildMember) { if (guildMember) {
await deleteGuild(guildMember.guildId); await deleteGuild(guildMember.guildId);
} }
await Promise.all([ await Promise.all([
Account.deleteOne({ _id: accountId }), Account.deleteOne({ _id: account._id }),
Friendship.deleteMany({ owner: accountId }), Friendship.deleteMany({ owner: account._id }),
Friendship.deleteMany({ friend: accountId }), Friendship.deleteMany({ friend: account._id }),
GuildMember.deleteMany({ accountId: accountId }), GuildMember.deleteMany({ accountId: account._id }),
Ignore.deleteMany({ ignorer: accountId }), Ignore.deleteMany({ ignorer: account._id }),
Ignore.deleteMany({ ignoree: accountId }), Ignore.deleteMany({ ignoree: account._id }),
Inbox.deleteMany({ ownerId: accountId }), Inbox.deleteMany({ ownerId: account._id }),
Inventory.deleteOne({ accountOwnerId: accountId }), Inventory.deleteOne({ accountOwnerId: account._id }),
Leaderboard.deleteMany({ ownerId: accountId }), Leaderboard.deleteMany({ ownerId: account._id }),
Loadout.deleteOne({ loadoutOwnerId: accountId }), Loadout.deleteOne({ loadoutOwnerId: account._id }),
PersonalRooms.deleteOne({ personalRoomsOwnerId: accountId }), PersonalRooms.deleteOne({ personalRoomsOwnerId: account._id }),
Ship.deleteMany({ ShipOwnerId: accountId }), Ship.deleteMany({ ShipOwnerId: account._id }),
Stats.deleteOne({ accountOwnerId: accountId }) Stats.deleteOne({ accountOwnerId: account._id })
]); ]);
sendWsBroadcastTo(accountId, { logged_out: true }); sendWsBroadcastTo(account._id.toString(), { logged_out: true });
res.end(); res.end();
}; };