SpaceNinjaServerAlexFork/src/controllers/custom/setGuildCheatController.ts
AMelonInsideLemon 86a63ace41 chore(webui): adjust checks for guild view requests (#2807)
Reviewed-on: OpenWF/SpaceNinjaServer#2807
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-24 08:41:04 -07:00

30 lines
1.0 KiB
TypeScript

import { GuildMember } from "../../models/guildModel.ts";
import { getGuildForRequestEx } 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, `GuildId`);
const guild = await getGuildForRequestEx(req, inventory);
const member = await GuildMember.findOne({ accountId: accountId, guildId: guild._id });
if (member) {
if (member.rank > 1) {
res.end();
return;
}
guild[payload.key] = payload.value;
await guild.save();
}
res.end();
};
interface ISetGuildCheatRequest {
key: keyof IGuildCheats;
value: boolean;
}