2024-05-04 15:42:25 +02:00
|
|
|
import { RequestHandler } from "express";
|
2024-05-28 13:45:06 +02:00
|
|
|
import { getAccountIdForRequest } from "@/src/services/loginService";
|
2024-05-04 15:42:25 +02:00
|
|
|
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
|
|
|
import { Inventory } from "@/src/models/inventoryModels/inventoryModel";
|
|
|
|
import { Guild } from "@/src/models/guildModel";
|
|
|
|
|
2025-01-03 09:06:50 +01:00
|
|
|
export const createGuildController: RequestHandler = async (req, res) => {
|
2024-05-28 13:45:06 +02:00
|
|
|
const accountId = await getAccountIdForRequest(req);
|
2024-06-24 12:37:28 +02:00
|
|
|
const payload = getJSONfromString(String(req.body)) as ICreateGuildRequest;
|
2024-05-04 15:42:25 +02:00
|
|
|
|
|
|
|
// Create guild on database
|
2024-05-06 15:19:42 +02:00
|
|
|
const guild = new Guild({
|
2024-05-04 15:42:25 +02:00
|
|
|
Name: payload.guildName
|
2024-05-16 01:34:38 +02:00
|
|
|
});
|
2024-05-04 15:42:25 +02:00
|
|
|
await guild.save();
|
|
|
|
|
|
|
|
// Update inventory
|
2024-05-28 13:45:06 +02:00
|
|
|
const inventory = await Inventory.findOne({ accountOwnerId: accountId });
|
2024-05-04 15:42:25 +02:00
|
|
|
if (inventory) {
|
|
|
|
// Set GuildId
|
|
|
|
inventory.GuildId = guild._id;
|
|
|
|
|
2024-05-16 01:34:38 +02:00
|
|
|
// Give clan key (TODO: This should only be a blueprint)
|
2024-05-04 15:42:25 +02:00
|
|
|
inventory.LevelKeys.push({
|
|
|
|
ItemType: "/Lotus/Types/Keys/DojoKey",
|
|
|
|
ItemCount: 1
|
|
|
|
});
|
|
|
|
|
|
|
|
await inventory.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
res.json(guild);
|
|
|
|
};
|
|
|
|
|
2025-01-03 09:06:50 +01:00
|
|
|
interface ICreateGuildRequest {
|
|
|
|
guildName: string;
|
|
|
|
}
|