SpaceNinjaServer/src/controllers/custom/deleteAccountController.ts
Sainan 7a3d442ba8
All checks were successful
Build / build (18) (pull_request) Successful in 39s
Build / build (20) (push) Successful in 37s
Build / build (18) (push) Successful in 1m11s
Build / build (22) (push) Successful in 1m20s
Build / build (20) (pull_request) Successful in 1m6s
Build / build (22) (pull_request) Successful in 35s
fix: use deleteMany for models where accountId is not unique when deleting account
2025-03-22 20:45:52 +01:00

27 lines
1.2 KiB
TypeScript

import { RequestHandler } from "express";
import { getAccountIdForRequest } from "@/src/services/loginService";
import { Account } from "@/src/models/loginModel";
import { Inbox } from "@/src/models/inboxModel";
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";
export const deleteAccountController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req);
// TODO: Handle the account being the creator of a guild
await Promise.all([
Account.deleteOne({ _id: accountId }),
GuildMember.deleteMany({ accountId: accountId }),
Inbox.deleteMany({ ownerId: accountId }),
Inventory.deleteOne({ accountOwnerId: accountId }),
Loadout.deleteOne({ loadoutOwnerId: accountId }),
PersonalRooms.deleteOne({ personalRoomsOwnerId: accountId }),
Ship.deleteMany({ ShipOwnerId: accountId }),
Stats.deleteOne({ accountOwnerId: accountId })
]);
res.end();
};