Add ICreateGuildRequest, assume the client formats it correctly
This commit is contained in:
parent
029fcb7540
commit
6c5020ac1b
@ -2,19 +2,14 @@ import { RequestHandler } from "express";
|
||||
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
||||
import { Inventory } from "@/src/models/inventoryModels/inventoryModel";
|
||||
import { Guild } from "@/src/models/guildModel";
|
||||
import { IGuild, guildDbToResponse } from "@/src/types/guildTypes";
|
||||
import { IGuild, guildDbToResponse, ICreateGuildRequest } from "@/src/types/guildTypes";
|
||||
|
||||
const createGuildController: RequestHandler = async (req, res) => {
|
||||
let payload = getJSONfromString(req.body.toString());
|
||||
|
||||
if (!payload.guildName) {
|
||||
res.status(400);
|
||||
return;
|
||||
}
|
||||
let payload: ICreateGuildRequest = getJSONfromString(req.body.toString());
|
||||
|
||||
// Create guild on database
|
||||
let guild = new Guild({
|
||||
Name: payload.guildName as string
|
||||
Name: payload.guildName
|
||||
} satisfies IGuild);
|
||||
await guild.save();
|
||||
|
||||
|
@ -18,3 +18,7 @@ export function guildDbToResponse(guild: IDatabaseGuild): IGuildResponse {
|
||||
(guild as IGuild as IGuildResponse)._id = toOid(guild._id);
|
||||
return guild as IGuild as IGuildResponse;
|
||||
}
|
||||
|
||||
export interface ICreateGuildRequest {
|
||||
guildName: string;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user