diff --git a/packages/backend/src/prelude/await-all.ts b/packages/backend/src/prelude/await-all.ts index ce11eb87..d81870a5 100644 --- a/packages/backend/src/prelude/await-all.ts +++ b/packages/backend/src/prelude/await-all.ts @@ -1,10 +1,12 @@ +import { unsafeCast } from "./unsafe-cast.js"; + export type Promiseable = { [K in keyof T]: Promise | T[K]; }; export async function awaitAll(obj: Promiseable): Promise { const target = {} as T; - const keys = Object.keys(obj) as unknown as (keyof T)[]; + const keys = unsafeCast<(keyof T)[]>(Object.keys(obj)); const values = Object.values(obj) as any[]; const resolvedValues = await Promise.all( diff --git a/packages/backend/src/prelude/unsafe-cast.ts b/packages/backend/src/prelude/unsafe-cast.ts new file mode 100644 index 00000000..f7e251fa --- /dev/null +++ b/packages/backend/src/prelude/unsafe-cast.ts @@ -0,0 +1,4 @@ +// unsafe type cast +export function unsafeCast(val: unknown): T { + return val as T; +} diff --git a/packages/backend/src/server/api/endpoints/admin/set-emoji-moderator.ts b/packages/backend/src/server/api/endpoints/admin/set-emoji-moderator.ts index 0bc79c03..8a4c2f16 100644 --- a/packages/backend/src/server/api/endpoints/admin/set-emoji-moderator.ts +++ b/packages/backend/src/server/api/endpoints/admin/set-emoji-moderator.ts @@ -1,6 +1,8 @@ import { Users } from "@/models/index.js"; import { publishInternalEvent } from "@/services/stream.js"; import define from "../../define.js"; +import type { EmojiModPerm } from "@/models/entities/user.js"; +import { unsafeCast } from "@/prelude/unsafe-cast.js"; export const meta = { tags: ["admin"], @@ -31,12 +33,8 @@ export default define(meta, paramDef, async (ps) => { ); } - const _emojiModPerm = - (ps.emojiModPerm as "unauthorized" | "add" | "mod" | "full") ?? - "unauthorized"; - await Users.update(user.id, { - emojiModPerm: _emojiModPerm, + emojiModPerm: unsafeCast(ps.emojiModPerm), }); publishInternalEvent("userChangeModeratorState", {