SpaceNinjaServer/src/controllers/api/getGuildDojoController.ts
Sainan 21164554a3
Some checks failed
Build / build (push) Has been cancelled
Build Docker image / docker (push) Has been cancelled
chore: some fixes to enter guild dojo on U15 (#2088)
Reviewed-on: #2088
Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com>
Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
2025-05-18 19:06:24 -07:00

36 lines
1.2 KiB
TypeScript

import { RequestHandler } from "express";
import { Types } from "mongoose";
import { Guild } from "@/src/models/guildModel";
import { getDojoClient } from "@/src/services/guildService";
import { Account } from "@/src/models/loginModel";
export const getGuildDojoController: RequestHandler = async (req, res) => {
const guildId = req.query.guildId as string;
const guild = await Guild.findById(guildId);
if (!guild) {
res.status(404).end();
return;
}
// Populate dojo info if not present
if (guild.DojoComponents.length == 0) {
guild.DojoComponents.push({
_id: new Types.ObjectId(),
pf: "/Lotus/Levels/ClanDojo/DojoHall.level",
ppf: "",
CompletionTime: new Date(Date.now()),
DecoCapacity: 600
});
await guild.save();
}
const payload: IGetGuildDojoRequest = req.body ? (JSON.parse(String(req.body)) as IGetGuildDojoRequest) : {};
const account = await Account.findById(req.query.accountId as string);
res.json(await getDojoClient(guild, 0, payload.ComponentId, account?.BuildLabel));
};
interface IGetGuildDojoRequest {
ComponentId?: string;
}