SpaceNinjaServer/src/controllers/custom/setGuildCheatController.ts
AMelonInsideLemon d64531f4b2 feat(webui): guild view (#2752)
Also moves guild-specific cheats to a switch for each guild
Closes #1403

Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com>
Reviewed-on: OpenWF/SpaceNinjaServer#2752
Reviewed-by: Sainan <63328889+sainan@users.noreply.github.com>
Co-authored-by: AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com>
Co-committed-by: AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com>
2025-09-09 23:55:10 -07:00

30 lines
1.1 KiB
TypeScript

import { GuildMember } from "../../models/guildModel.ts";
import { getGuildForRequestEx, hasAccessToDojo } from "../../services/guildService.ts";
import { getInventory } from "../../services/inventoryService.ts";
import { getAccountIdForRequest } from "../../services/loginService.ts";
import type { IGuildCheats } from "../../types/guildTypes.ts";
import type { RequestHandler } from "express";
export const setGuildCheatController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req);
const payload = req.body as ISetGuildCheatRequest;
const inventory = await getInventory(accountId, `${payload.key} GuildId LevelKeys`);
const guild = await getGuildForRequestEx(req, inventory);
const member = await GuildMember.findOne({ accountId: accountId, guildId: guild._id });
if (member) {
if (!hasAccessToDojo(inventory) || member.rank > 1) {
res.end();
return;
}
guild[payload.key] = payload.value;
await guild.save();
}
res.end();
};
interface ISetGuildCheatRequest {
key: keyof IGuildCheats;
value: boolean;
}