SpaceNinjaServer/src/controllers/custom/deleteAccountController.ts

29 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-12-23 03:34:14 +01:00
import { RequestHandler } from "express";
import { getAccountIdForRequest } from "@/src/services/loginService";
import { Account } from "@/src/models/loginModel";
import { Inbox } from "@/src/models/inboxModel";
2024-12-23 03:34:14 +01:00
import { Inventory } from "@/src/models/inventoryModels/inventoryModel";
import { Loadout } from "@/src/models/inventoryModels/loadoutModel";
import { PersonalRooms } from "@/src/models/personalRoomsModel";
import { Ship } from "@/src/models/shipModel";
import { Stats } from "@/src/models/statsModel";
import { GuildMember } from "@/src/models/guildModel";
2025-03-24 14:17:07 +01:00
import { Leaderboard } from "@/src/models/leaderboardModel";
2024-12-23 03:34:14 +01:00
export const deleteAccountController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req);
// TODO: Handle the account being the creator of a guild
2024-12-23 03:34:14 +01:00
await Promise.all([
Account.deleteOne({ _id: accountId }),
GuildMember.deleteMany({ accountId: accountId }),
Inbox.deleteMany({ ownerId: accountId }),
2024-12-23 03:34:14 +01:00
Inventory.deleteOne({ accountOwnerId: accountId }),
2025-03-24 14:17:07 +01:00
Leaderboard.deleteMany({ accountId: accountId }),
2024-12-23 03:34:14 +01:00
Loadout.deleteOne({ loadoutOwnerId: accountId }),
PersonalRooms.deleteOne({ personalRoomsOwnerId: accountId }),
Ship.deleteMany({ ShipOwnerId: accountId }),
Stats.deleteOne({ accountOwnerId: accountId })
2024-12-23 03:34:14 +01:00
]);
res.end();
};