SpaceNinjaServer/src/controllers/api/createGuildController.ts

33 lines
990 B
TypeScript
Raw Normal View History

import { RequestHandler } from "express";
2024-05-28 13:45:06 +02:00
import { getAccountIdForRequest } from "@/src/services/loginService";
import { getJSONfromString } from "@/src/helpers/stringHelpers";
import { Guild, GuildMember } from "@/src/models/guildModel";
import { updateInventoryForConfirmedGuildJoin } from "@/src/services/guildService";
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);
const payload = getJSONfromString<ICreateGuildRequest>(String(req.body));
// Create guild on database
const guild = new Guild({
Name: payload.guildName
});
await guild.save();
// Create guild member on database
await GuildMember.insertOne({
accountId: accountId,
guildId: guild._id,
status: 0,
rank: 0
});
await updateInventoryForConfirmedGuildJoin(accountId, guild._id);
res.json(guild);
};
2025-01-03 09:06:50 +01:00
interface ICreateGuildRequest {
guildName: string;
}