mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-04-24 11:29:12 +00:00
* feat(design-system): add editor skeletons * use css media queries rather than JS media queries * init remake * feat: add basis of toggle atom * finish toggle * use pointer cursor with toggle * sync * feat: add server message in editor * cleanup storybook * add short editor item and data model for categories * chore: fix build by moving jest version downward * chore: remove old category editor * chore: fix EditorCategoryShort index * add editor wiring and styling updates * fix linting issues
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import { GuildDataUpdate, SessionData, UserGuildPermissions } from '@roleypoly/types';
|
|
import { withSession } from '../utils/api-tools';
|
|
import { getGuildData } from '../utils/guild';
|
|
import { GuildData } from '../utils/kv';
|
|
import { lowPermissions, missingParameters, notFound, ok } from '../utils/responses';
|
|
|
|
export const UpdateGuild = withSession(
|
|
(session: SessionData) =>
|
|
async (request: Request): Promise<Response> => {
|
|
const url = new URL(request.url);
|
|
const [, , guildID] = url.pathname.split('/');
|
|
if (!guildID) {
|
|
return missingParameters();
|
|
}
|
|
|
|
const guildUpdate = (await request.json()) as GuildDataUpdate;
|
|
|
|
const guild = session.guilds.find((guild) => guild.id === guildID);
|
|
if (!guild) {
|
|
return notFound();
|
|
}
|
|
|
|
if (
|
|
guild?.permissionLevel !== UserGuildPermissions.Manager &&
|
|
guild?.permissionLevel !== UserGuildPermissions.Admin
|
|
) {
|
|
return lowPermissions();
|
|
}
|
|
|
|
const newGuildData = {
|
|
...(await getGuildData(guildID)),
|
|
...guildUpdate,
|
|
};
|
|
|
|
await GuildData.put(guildID, newGuildData);
|
|
|
|
return ok();
|
|
}
|
|
);
|