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";
|
2025-03-10 16:40:40 -07:00
|
|
|
import { Guild, GuildMember } from "@/src/models/guildModel";
|
2025-03-11 10:31:56 -07:00
|
|
|
import {
|
|
|
|
createUniqueClanName,
|
|
|
|
getGuildClient,
|
|
|
|
updateInventoryForConfirmedGuildJoin
|
|
|
|
} from "@/src/services/guildService";
|
2024-05-04 15:42:25 +02:00
|
|
|
|
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);
|
2025-01-24 14:27:10 +01:00
|
|
|
const payload = getJSONfromString<ICreateGuildRequest>(String(req.body));
|
2024-05-04 15:42:25 +02:00
|
|
|
|
|
|
|
// Create guild on database
|
2024-05-06 15:19:42 +02:00
|
|
|
const guild = new Guild({
|
2025-03-11 10:31:56 -07:00
|
|
|
Name: await createUniqueClanName(payload.guildName)
|
2024-05-16 01:34:38 +02:00
|
|
|
});
|
2024-05-04 15:42:25 +02:00
|
|
|
await guild.save();
|
|
|
|
|
2025-03-10 16:40:40 -07:00
|
|
|
// Create guild member on database
|
|
|
|
await GuildMember.insertOne({
|
|
|
|
accountId: accountId,
|
|
|
|
guildId: guild._id,
|
|
|
|
status: 0,
|
|
|
|
rank: 0
|
|
|
|
});
|
2024-05-04 15:42:25 +02:00
|
|
|
|
2025-03-10 16:40:40 -07:00
|
|
|
await updateInventoryForConfirmedGuildJoin(accountId, guild._id);
|
2024-05-04 15:42:25 +02:00
|
|
|
|
2025-03-29 18:01:52 +01:00
|
|
|
res.json({
|
|
|
|
...(await getGuildClient(guild, accountId)),
|
|
|
|
InventoryChanges: {
|
|
|
|
Recipes: [
|
|
|
|
{
|
|
|
|
ItemType: "/Lotus/Types/Keys/DojoKeyBlueprint",
|
|
|
|
ItemCount: 1
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
});
|
2024-05-04 15:42:25 +02:00
|
|
|
};
|
|
|
|
|
2025-01-03 09:06:50 +01:00
|
|
|
interface ICreateGuildRequest {
|
|
|
|
guildName: string;
|
|
|
|
}
|