SpaceNinjaServer/src/controllers/api/getGuildController.ts

26 lines
794 B
TypeScript
Raw Normal View History

2024-05-02 23:38:32 +02:00
import { RequestHandler } from "express";
import { Inventory } from "@/src/models/inventoryModels/inventoryModel";
import { Guild } from "@/src/models/guildModel";
2024-05-02 23:38:32 +02:00
const getGuildController: RequestHandler = async (req, res) => {
if (!req.query.accountId) {
res.status(400).json({ error: "accountId was not provided" });
return;
}
const inventory = await Inventory.findOne({ accountOwnerId: req.query.accountId });
if (!inventory) {
res.status(400).json({ error: "inventory was undefined" });
return;
}
if (inventory.GuildId) {
const guild = await Guild.findOne({ _id: inventory.GuildId });
if (guild) {
res.json(guild);
return;
}
}
2024-05-02 23:38:32 +02:00
res.json({});
};
export { getGuildController };