diff --git a/src/api/index.ts b/src/api/index.ts index 2c402a89b..67ae94799 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -1,4 +1,4 @@ -import express, { Express, Request, Response, NextFunction, Router } from 'express'; +import express, { Express, Request, Response, NextFunction } from 'express'; import passport from "passport"; import Logger from '../structures/Logger'; import config from '../config'; @@ -21,7 +21,7 @@ export class DiscordDashboard { this.app.use(express.urlencoded({ extended: true })); this.app.use(this.errorHandler.bind(this)); this.app.use(cors({ - origin: config.dashboard.host + ':' + config.dashboard.port, + origin: config.dashboard.website, credentials: true })); this.app.use(session({ diff --git a/src/api/routes/guilds/GuildRouter.ts b/src/api/routes/guilds/GuildRouter.ts index 10250477a..76aa66d00 100644 --- a/src/api/routes/guilds/GuildRouter.ts +++ b/src/api/routes/guilds/GuildRouter.ts @@ -1,6 +1,7 @@ import { Router, Request, Response } from "express"; import { IsAuth } from "../../middlewares/Middlewares"; import { getGuild, getGuildMembers } from "../../services/guilds/GuildServices"; +import ServerData from "../../../database/server"; class GuildRouter { @@ -12,6 +13,7 @@ class GuildRouter { private initializeRoutes() { this.router.get("/:id", IsAuth, this.getGuild); this.router.get("/:id/members", IsAuth, this.getGuildsMembers); + this.router.post("/:id/prefix", IsAuth, this.updateGuildPrefix); } private async getGuild(req: Request, res: Response) { const guild = await getGuild(req.params.id); @@ -21,6 +23,12 @@ class GuildRouter { const guild = await getGuildMembers(req.params.id); return res.send(guild); } + + private async updateGuildPrefix(req: Request, res: Response) { + console.log(req.params.id, req.body.prefix); + await ServerData.setPrefix(req.params.id, req.body.prefix); + return res.sendStatus(200); + } } const guildRouter = new GuildRouter();