Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion packages/api/src/routers/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,48 @@ import { Routes } from "discord-api-types/v10";
import { z } from "zod";

import {
ALLOWED_FORM_ASSIGNABLE_DISC_ROLES,
generateFundingRequestEmailHtml,
RECRUITING_CHANNEL,
TEAM_MAP,
} from "@forge/consts/knight-hacks";

import { protectedProcedure } from "../trpc";
import { discord, sendEmail } from "../utils";
import { discord, KNIGHTHACKS_GUILD_ID, sendEmail } from "../utils";

// Miscellaneous routes (primarily for form integrations)
export const miscRouter = {
addRoleId: protectedProcedure
.meta({
id: "addRoleId",
inputSchema: z.object({
roleId: z.string(),
}),
})
.input(
z.object({
roleId: z.string(),
}),
)
.mutation(async ({ input, ctx }) => {
if (!ALLOWED_FORM_ASSIGNABLE_DISC_ROLES.includes(input.roleId)) {
throw new Error(
`Roleid: ${input.roleId} is not assignable through forms for security purposes. Add to consts and make a PR if this is a mistake.`,
);
}

try {
const discId = ctx.session.user.discordUserId;
await discord.put(
Routes.guildMemberRole(KNIGHTHACKS_GUILD_ID, discId, input.roleId),
);
} catch {
throw new Error(
`Could not assign role ${input.roleId} to user ${ctx.session.user.name}`,
);
}
}),

recruitingUpdate: protectedProcedure
.meta({
id: "recruitingUpdate",
Expand Down
2 changes: 2 additions & 0 deletions packages/consts/src/knight-hacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7055,3 +7055,5 @@ export const TEAM_MAP = [
director_role: "1244790444626280550",
},
];

export const ALLOWED_FORM_ASSIGNABLE_DISC_ROLES = ["1467281189088788489"];
Loading