diff options
author | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-09-26 22:29:30 +1000 |
---|---|---|
committer | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-09-26 22:41:21 +1000 |
commit | 99ee7e9400f06e8718612d8b52d15215dc620774 (patch) | |
tree | 08de8c5d3985b9c2eaa419f5198f891ecd82d012 /src/api/util/handlers/route.ts | |
parent | Remove the cdn storage location log (diff) | |
download | server-99ee7e9400f06e8718612d8b52d15215dc620774.tar.xz |
Prettier
Diffstat (limited to 'src/api/util/handlers/route.ts')
-rw-r--r-- | src/api/util/handlers/route.ts | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/src/api/util/handlers/route.ts b/src/api/util/handlers/route.ts index c245b411..5dcae953 100644 --- a/src/api/util/handlers/route.ts +++ b/src/api/util/handlers/route.ts @@ -10,7 +10,7 @@ import { PermissionResolvable, Permissions, RightResolvable, - Rights + Rights, } from "@fosscord/util"; import { NextFunction, Request, Response } from "express"; import { AnyValidateFunction } from "ajv/dist/core"; @@ -23,7 +23,11 @@ declare global { } } -export type RouteResponse = { status?: number; body?: `${string}Response`; headers?: Record<string, string> }; +export type RouteResponse = { + status?: number; + body?: `${string}Response`; + headers?: Record<string, string>; +}; export interface RouteOptions { permission?: PermissionResolvable; @@ -48,11 +52,17 @@ export function route(opts: RouteOptions) { return async (req: Request, res: Response, next: NextFunction) => { if (opts.permission) { const required = new Permissions(opts.permission); - req.permission = await getPermission(req.user_id, req.params.guild_id, req.params.channel_id); + req.permission = await getPermission( + req.user_id, + req.params.guild_id, + req.params.channel_id, + ); // bitfield comparison: check if user lacks certain permission if (!req.permission.has(required)) { - throw DiscordApiErrors.MISSING_PERMISSIONS.withParams(opts.permission as string); + throw DiscordApiErrors.MISSING_PERMISSIONS.withParams( + opts.permission as string, + ); } } @@ -61,15 +71,26 @@ export function route(opts: RouteOptions) { req.rights = await getRights(req.user_id); if (!req.rights || !req.rights.has(required)) { - throw FosscordApiErrors.MISSING_RIGHTS.withParams(opts.right as string); + throw FosscordApiErrors.MISSING_RIGHTS.withParams( + opts.right as string, + ); } } if (validate) { const valid = validate(normalizeBody(req.body)); if (!valid) { - const fields: Record<string, { code?: string; message: string }> = {}; - validate.errors?.forEach((x) => (fields[x.instancePath.slice(1)] = { code: x.keyword, message: x.message || "" })); + const fields: Record< + string, + { code?: string; message: string } + > = {}; + validate.errors?.forEach( + (x) => + (fields[x.instancePath.slice(1)] = { + code: x.keyword, + message: x.message || "", + }), + ); throw FieldErrors(fields); } } |