forked from OpenWF/SpaceNinjaServer
		
	chore(webui): remove administratorNames entry when deleting account (#2820)
Closes #2819 Reviewed-on: OpenWF/SpaceNinjaServer#2820 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									17e1eb86dd
								
							
						
					
					
						commit
						a64c5ea3c1
					
				@ -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();
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user