diff --git a/app/features/admin/actions/admin.server.ts b/app/features/admin/actions/admin.server.ts index 70bb5a74e..b242637bc 100644 --- a/app/features/admin/actions/admin.server.ts +++ b/app/features/admin/actions/admin.server.ts @@ -8,7 +8,7 @@ import * as UserRepository from "~/features/user-page/UserRepository.server"; import { requireRole } from "~/modules/permissions/guards.server"; import { errorToast, - notFoundIfFalsy, + notFoundIfNullish, parseRequestPayload, successToast, } from "~/utils/remix.server"; @@ -129,7 +129,7 @@ export const action = async ({ request }: ActionFunctionArgs) => { case "BAN_USER": { requireRole("STAFF"); - const bannedUser = notFoundIfFalsy( + const bannedUser = notFoundIfNullish( await UserRepository.findLeanById(data.user), ); const banExpiresAt = data.duration ? new Date(data.duration) : null; @@ -156,7 +156,7 @@ export const action = async ({ request }: ActionFunctionArgs) => { case "UNBAN_USER": { requireRole("STAFF"); - const unbannedUser = notFoundIfFalsy( + const unbannedUser = notFoundIfNullish( await UserRepository.findLeanById(data.user), ); diff --git a/app/features/api-public/routes/org.$id.ts b/app/features/api-public/routes/org.$id.ts index 555d489ef..28c127a1d 100644 --- a/app/features/api-public/routes/org.$id.ts +++ b/app/features/api-public/routes/org.$id.ts @@ -3,7 +3,7 @@ import type { LoaderFunctionArgs } from "react-router"; import { z } from "zod"; import { db } from "~/db/sql"; import { concatUserSubmittedImagePrefix } from "~/utils/kysely.server"; -import { notFoundIfFalsy, parseParams } from "~/utils/remix.server"; +import { notFoundIfNullish, parseParams } from "~/utils/remix.server"; import { id } from "~/utils/zod"; import type { GetTournamentOrganizationResponse } from "../schema"; @@ -14,7 +14,7 @@ const paramsSchema = z.object({ export const loader = async ({ params }: LoaderFunctionArgs) => { const { id } = parseParams({ params, schema: paramsSchema }); - const organization = notFoundIfFalsy( + const organization = notFoundIfNullish( await db .selectFrom("TournamentOrganization") .leftJoin( diff --git a/app/features/api-public/routes/sendouq.match.$matchId.ts b/app/features/api-public/routes/sendouq.match.$matchId.ts index cebda392e..04b57a6bc 100644 --- a/app/features/api-public/routes/sendouq.match.$matchId.ts +++ b/app/features/api-public/routes/sendouq.match.$matchId.ts @@ -2,7 +2,7 @@ import type { LoaderFunctionArgs } from "react-router"; import { z } from "zod"; import * as SQMatchRepository from "~/features/sendouq-match/SQMatchRepository.server"; import { getFixedTForLanguage } from "~/modules/i18n/i18next.server"; -import { notFoundIfFalsy, parseParams } from "~/utils/remix.server"; +import { notFoundIfNullish, parseParams } from "~/utils/remix.server"; import { id } from "~/utils/zod"; import type { GetSendouqMatchResponse, MapListMap } from "../schema"; @@ -16,7 +16,7 @@ export const loader = async ({ params }: LoaderFunctionArgs) => { schema: paramsSchema, }); - const match = notFoundIfFalsy(await SQMatchRepository.findById(matchId)); + const match = notFoundIfNullish(await SQMatchRepository.findById(matchId)); const t = await getFixedTForLanguage("en", ["game-misc"]); diff --git a/app/features/api-public/routes/team.$id.ts b/app/features/api-public/routes/team.$id.ts index 610daf8e2..4ec67dd61 100644 --- a/app/features/api-public/routes/team.$id.ts +++ b/app/features/api-public/routes/team.$id.ts @@ -2,7 +2,7 @@ import type { LoaderFunctionArgs } from "react-router"; import { z } from "zod"; import { db } from "~/db/sql"; import { concatUserSubmittedImagePrefix } from "~/utils/kysely.server"; -import { notFoundIfFalsy, parseParams } from "~/utils/remix.server"; +import { notFoundIfNullish, parseParams } from "~/utils/remix.server"; import { id } from "~/utils/zod"; import type { GetTeamResponse } from "../schema"; @@ -13,7 +13,7 @@ const paramsSchema = z.object({ export const loader = async ({ params }: LoaderFunctionArgs) => { const { id: teamId } = parseParams({ params, schema: paramsSchema }); - const team = notFoundIfFalsy( + const team = notFoundIfNullish( await db .selectFrom("Team") .leftJoin( diff --git a/app/features/api-public/routes/tournament-match.$id.ts b/app/features/api-public/routes/tournament-match.$id.ts index 354fa3606..edc87d4a3 100644 --- a/app/features/api-public/routes/tournament-match.$id.ts +++ b/app/features/api-public/routes/tournament-match.$id.ts @@ -8,7 +8,7 @@ import { tournamentFromDBCached } from "~/features/tournament-bracket/core/Tourn import { resolveMapList } from "~/features/tournament-match/core/mapList.server"; import { getFixedTForLanguage } from "~/modules/i18n/i18next.server"; import { logger } from "~/utils/logger"; -import { notFoundIfFalsy, parseParams } from "~/utils/remix.server"; +import { notFoundIfNullish, parseParams } from "~/utils/remix.server"; import { id } from "~/utils/zod"; import type { GetTournamentMatchResponse } from "../schema"; @@ -23,7 +23,7 @@ export const loader = async ({ params }: LoaderFunctionArgs) => { schema: paramsSchema, }); - const match = notFoundIfFalsy( + const match = notFoundIfNullish( await db .selectFrom("TournamentMatch") .innerJoin( diff --git a/app/features/api-public/routes/tournament.$id.brackets.$bidx.standings.ts b/app/features/api-public/routes/tournament.$id.brackets.$bidx.standings.ts index f5155dcda..27ab6a913 100644 --- a/app/features/api-public/routes/tournament.$id.brackets.$bidx.standings.ts +++ b/app/features/api-public/routes/tournament.$id.brackets.$bidx.standings.ts @@ -1,7 +1,7 @@ import type { LoaderFunctionArgs } from "react-router"; import { z } from "zod"; import { tournamentFromDB } from "~/features/tournament-bracket/core/Tournament.server"; -import { notFoundIfFalsy, parseParams } from "~/utils/remix.server"; +import { notFoundIfNullish, parseParams } from "~/utils/remix.server"; import { id } from "~/utils/zod"; import type { GetTournamentBracketStandingsResponse } from "../schema"; @@ -18,8 +18,8 @@ export const loader = async ({ params }: LoaderFunctionArgs) => { tournamentId: id, }); - const bracket = notFoundIfFalsy(tournament.bracketByIdx(bidx)); - notFoundIfFalsy(!bracket.preview); + const bracket = notFoundIfNullish(tournament.bracketByIdx(bidx)); + if (bracket.preview) throw new Response(null, { status: 404 }); const result: GetTournamentBracketStandingsResponse = { standings: bracket.standings.map((standing) => ({ diff --git a/app/features/api-public/routes/tournament.$id.brackets.$bidx.ts b/app/features/api-public/routes/tournament.$id.brackets.$bidx.ts index 7e29e8ff4..fb7be95ed 100644 --- a/app/features/api-public/routes/tournament.$id.brackets.$bidx.ts +++ b/app/features/api-public/routes/tournament.$id.brackets.$bidx.ts @@ -2,7 +2,7 @@ import type { LoaderFunctionArgs } from "react-router"; import { z } from "zod"; import type { Bracket } from "~/features/tournament-bracket/core/Bracket"; import { tournamentFromDB } from "~/features/tournament-bracket/core/Tournament.server"; -import { notFoundIfFalsy, parseParams } from "~/utils/remix.server"; +import { notFoundIfNullish, parseParams } from "~/utils/remix.server"; import { id } from "~/utils/zod"; import type { GetTournamentBracketResponse } from "../schema"; @@ -19,7 +19,7 @@ export const loader = async ({ params }: LoaderFunctionArgs) => { tournamentId: id, }); - const bracket = notFoundIfFalsy(tournament.bracketByIdx(bidx)); + const bracket = notFoundIfNullish(tournament.bracketByIdx(bidx)); const result: GetTournamentBracketResponse = { data: bracket.data, diff --git a/app/features/api-public/routes/tournament.$id.casted.ts b/app/features/api-public/routes/tournament.$id.casted.ts index 0f96cae62..9b28f72b4 100644 --- a/app/features/api-public/routes/tournament.$id.casted.ts +++ b/app/features/api-public/routes/tournament.$id.casted.ts @@ -1,7 +1,7 @@ import type { LoaderFunctionArgs } from "react-router"; import { z } from "zod"; import { db } from "~/db/sql"; -import { notFoundIfFalsy, parseParams } from "~/utils/remix.server"; +import { notFoundIfNullish, parseParams } from "~/utils/remix.server"; import { id } from "~/utils/zod"; import type { GetCastedTournamentMatchesResponse } from "../schema"; @@ -15,7 +15,7 @@ export const loader = async ({ params }: LoaderFunctionArgs) => { schema: paramsSchema, }); - const tournament = notFoundIfFalsy( + const tournament = notFoundIfNullish( await db .selectFrom("Tournament") .select(["Tournament.castedMatchesInfo"]) diff --git a/app/features/api-public/routes/tournament.$id.streams.ts b/app/features/api-public/routes/tournament.$id.streams.ts index 9bc5bdd5b..22c7bbcd7 100644 --- a/app/features/api-public/routes/tournament.$id.streams.ts +++ b/app/features/api-public/routes/tournament.$id.streams.ts @@ -3,7 +3,7 @@ import { jsonArrayFrom } from "kysely/helpers/sqlite"; import type { LoaderFunctionArgs } from "react-router"; import { z } from "zod"; import { db } from "~/db/sql"; -import { notFoundIfFalsy, parseParams } from "~/utils/remix.server"; +import { notFoundIfNullish, parseParams } from "~/utils/remix.server"; import { id } from "~/utils/zod"; import type { GetTournamentStreamsResponse } from "../schema"; @@ -17,7 +17,7 @@ export const loader = async ({ params }: LoaderFunctionArgs) => { schema: paramsSchema, }); - const tournament = notFoundIfFalsy( + const tournament = notFoundIfNullish( await db .selectFrom("Tournament") .select([ diff --git a/app/features/api-public/routes/tournament.$id.ts b/app/features/api-public/routes/tournament.$id.ts index 713892ca6..aa0771d16 100644 --- a/app/features/api-public/routes/tournament.$id.ts +++ b/app/features/api-public/routes/tournament.$id.ts @@ -3,7 +3,7 @@ import type { LoaderFunctionArgs } from "react-router"; import { z } from "zod"; import { db } from "~/db/sql"; import { databaseTimestampToDate } from "~/utils/dates"; -import { notFoundIfFalsy, parseParams } from "~/utils/remix.server"; +import { notFoundIfNullish, parseParams } from "~/utils/remix.server"; import { id } from "~/utils/zod"; import type { GetTournamentResponse } from "../schema"; @@ -14,7 +14,7 @@ const paramsSchema = z.object({ export const loader = async ({ params }: LoaderFunctionArgs) => { const { id } = parseParams({ params, schema: paramsSchema }); - const tournament = notFoundIfFalsy( + const tournament = notFoundIfNullish( await db .selectFrom("Tournament") .innerJoin("CalendarEvent", "CalendarEvent.tournamentId", "Tournament.id") diff --git a/app/features/api-public/routes/user.$identifier.ids.ts b/app/features/api-public/routes/user.$identifier.ids.ts index 833f0610c..be9f9b38d 100644 --- a/app/features/api-public/routes/user.$identifier.ids.ts +++ b/app/features/api-public/routes/user.$identifier.ids.ts @@ -1,7 +1,7 @@ import type { LoaderFunctionArgs } from "react-router"; import { z } from "zod/v4"; import { identifierToUserIdQuery } from "~/features/user-page/UserRepository.server"; -import { notFoundIfFalsy, parseParams } from "~/utils/remix.server"; +import { notFoundIfNullish, parseParams } from "~/utils/remix.server"; import type { GetUserIdsResponse } from "../schema"; const paramsSchema = z.object({ @@ -11,7 +11,7 @@ const paramsSchema = z.object({ export const loader = async ({ params }: LoaderFunctionArgs) => { const { identifier } = parseParams({ params, schema: paramsSchema }); - const user = notFoundIfFalsy( + const user = notFoundIfNullish( await identifierToUserIdQuery(identifier) .select(["User.discordId", "User.customUrl"]) .executeTakeFirst(), diff --git a/app/features/api-public/routes/user.$identifier.ts b/app/features/api-public/routes/user.$identifier.ts index e51cd5c3b..90aa843cf 100644 --- a/app/features/api-public/routes/user.$identifier.ts +++ b/app/features/api-public/routes/user.$identifier.ts @@ -8,7 +8,7 @@ import { peakXpOverallSql } from "~/features/top-search/XRankPlacementRepository import * as UserRepository from "~/features/user-page/UserRepository.server"; import { getFixedTForLanguage } from "~/modules/i18n/i18next.server"; import { safeNumberParse } from "~/utils/number"; -import { notFoundIfFalsy, parseParams } from "~/utils/remix.server"; +import { notFoundIfNullish, parseParams } from "~/utils/remix.server"; import { badgeUrl } from "~/utils/urls"; import type { GetUserResponse } from "../schema"; @@ -20,7 +20,7 @@ export const loader = async ({ params }: LoaderFunctionArgs) => { const t = await getFixedTForLanguage("en", ["weapons"]); const { identifier } = parseParams({ params, schema: paramsSchema }); - const user = notFoundIfFalsy( + const user = notFoundIfNullish( await db .selectFrom("User") .leftJoin("PlusTier", "PlusTier.userId", "User.id") diff --git a/app/features/articles/loaders/a.$slug.server.ts b/app/features/articles/loaders/a.$slug.server.ts index 4129b9b5d..0f1640f7e 100644 --- a/app/features/articles/loaders/a.$slug.server.ts +++ b/app/features/articles/loaders/a.$slug.server.ts @@ -1,12 +1,12 @@ import type { LoaderFunctionArgs } from "react-router"; import invariant from "~/utils/invariant"; -import { notFoundIfFalsy } from "~/utils/remix.server"; +import { notFoundIfNullish } from "~/utils/remix.server"; import { articleBySlug } from "../core/bySlug.server"; export const loader = ({ params }: LoaderFunctionArgs) => { invariant(params.slug); - const article = notFoundIfFalsy(articleBySlug(params.slug)); + const article = notFoundIfNullish(articleBySlug(params.slug)); return { ...article, slug: params.slug }; }; diff --git a/app/features/badges/actions/badges.$id.edit.server.ts b/app/features/badges/actions/badges.$id.edit.server.ts index bc67ab930..76fa4db83 100644 --- a/app/features/badges/actions/badges.$id.edit.server.ts +++ b/app/features/badges/actions/badges.$id.edit.server.ts @@ -7,7 +7,7 @@ import { requireRole, } from "~/modules/permissions/guards.server"; import { diff } from "~/utils/arrays"; -import { notFoundIfFalsy, parseRequestPayload } from "~/utils/remix.server"; +import { notFoundIfNullish, parseRequestPayload } from "~/utils/remix.server"; import { assertUnreachable } from "~/utils/types"; import { badgePage } from "~/utils/urls"; import { actualNumber } from "~/utils/zod"; @@ -20,7 +20,7 @@ export const action: ActionFunction = async ({ request, params }) => { schema: editBadgeActionSchema, }); const badgeId = z.preprocess(actualNumber, z.number()).parse(params.id); - const badge = notFoundIfFalsy(await BadgeRepository.findById(badgeId)); + const badge = notFoundIfNullish(await BadgeRepository.findById(badgeId)); switch (data._action) { case "MANAGERS": { diff --git a/app/features/badges/loaders/badges.$id.server.ts b/app/features/badges/loaders/badges.$id.server.ts index 98559fad1..be07960da 100644 --- a/app/features/badges/loaders/badges.$id.server.ts +++ b/app/features/badges/loaders/badges.$id.server.ts @@ -1,6 +1,6 @@ import type { LoaderFunctionArgs } from "react-router"; import type { SerializeFrom } from "~/utils/remix"; -import { notFoundIfFalsy, parseParams } from "~/utils/remix.server"; +import { notFoundIfNullish, parseParams } from "~/utils/remix.server"; import { idObject } from "~/utils/zod"; import * as BadgeRepository from "../BadgeRepository.server"; @@ -10,7 +10,7 @@ export const loader = async ({ params }: LoaderFunctionArgs) => { params, schema: idObject, }); - const badge = notFoundIfFalsy(await BadgeRepository.findById(id)); + const badge = notFoundIfNullish(await BadgeRepository.findById(id)); return { badge, diff --git a/app/features/build-stats/loaders/builds.$slug.popular.server.ts b/app/features/build-stats/loaders/builds.$slug.popular.server.ts index 7b0d81c12..6a1fc00f3 100644 --- a/app/features/build-stats/loaders/builds.$slug.popular.server.ts +++ b/app/features/build-stats/loaders/builds.$slug.popular.server.ts @@ -4,14 +4,14 @@ import * as BuildRepository from "~/features/builds/BuildRepository.server"; import { getServerTFunction } from "~/modules/i18n/i18next.server"; import { weaponIdToType } from "~/modules/in-game-lists/weapon-ids"; import { cache, IN_MILLISECONDS, ttl } from "~/utils/cache.server"; -import { notFoundIfNullLike } from "~/utils/remix.server"; +import { notFoundIfNullish } from "~/utils/remix.server"; import { weaponNameSlugToId } from "~/utils/unslugify.server"; import { popularBuilds } from "../build-stats-utils"; export const loader = async ({ params }: LoaderFunctionArgs) => { const t = getServerTFunction(["builds", "weapons"]); const slug = params.slug; - const weaponId = notFoundIfNullLike(weaponNameSlugToId(slug)); + const weaponId = notFoundIfNullish(weaponNameSlugToId(slug)); if (weaponIdToType(weaponId) === "ALT_SKIN") { throw new Response(null, { status: 404 }); diff --git a/app/features/build-stats/loaders/builds.$slug.stats.server.ts b/app/features/build-stats/loaders/builds.$slug.stats.server.ts index 1296a68cd..d60075ff3 100644 --- a/app/features/build-stats/loaders/builds.$slug.stats.server.ts +++ b/app/features/build-stats/loaders/builds.$slug.stats.server.ts @@ -4,13 +4,13 @@ import * as BuildRepository from "~/features/builds/BuildRepository.server"; import { getServerTFunction } from "~/modules/i18n/i18next.server"; import { weaponIdToType } from "~/modules/in-game-lists/weapon-ids"; import { cache } from "~/utils/cache.server"; -import { notFoundIfNullLike } from "~/utils/remix.server"; +import { notFoundIfNullish } from "~/utils/remix.server"; import { weaponNameSlugToId } from "~/utils/unslugify.server"; import { abilityPointCountsToAverages } from "../build-stats-utils"; export const loader = async ({ params }: LoaderFunctionArgs) => { const t = getServerTFunction(["builds", "weapons"]); - const weaponId = notFoundIfNullLike(weaponNameSlugToId(params.slug)); + const weaponId = notFoundIfNullish(weaponNameSlugToId(params.slug)); if (weaponIdToType(weaponId) === "ALT_SKIN") { throw new Response(null, { status: 404 }); diff --git a/app/features/calendar/actions/calendar.$id.report-winners.server.ts b/app/features/calendar/actions/calendar.$id.report-winners.server.ts index 12ad95966..d491e4752 100644 --- a/app/features/calendar/actions/calendar.$id.report-winners.server.ts +++ b/app/features/calendar/actions/calendar.$id.report-winners.server.ts @@ -4,7 +4,7 @@ import { requireUser } from "~/features/auth/core/user.server"; import * as CalendarRepository from "~/features/calendar/CalendarRepository.server"; import { errorToastIfFalsy, - notFoundIfFalsy, + notFoundIfNullish, parseParams, safeParseRequestFormData, } from "~/utils/remix.server"; @@ -30,7 +30,7 @@ export const action: ActionFunction = async (args) => { }; } - const event = notFoundIfFalsy(await CalendarRepository.findById(params.id)); + const event = notFoundIfNullish(await CalendarRepository.findById(params.id)); errorToastIfFalsy( canReportCalendarEventWinners({ user, diff --git a/app/features/calendar/actions/calendar.$id.server.ts b/app/features/calendar/actions/calendar.$id.server.ts index 36bd57a4d..7425e268e 100644 --- a/app/features/calendar/actions/calendar.$id.server.ts +++ b/app/features/calendar/actions/calendar.$id.server.ts @@ -9,7 +9,7 @@ import { tournamentManagerData, } from "~/features/tournament-bracket/core/Tournament.server"; import { databaseTimestampToDate } from "~/utils/dates"; -import { errorToastIfFalsy, notFoundIfFalsy } from "~/utils/remix.server"; +import { errorToastIfFalsy, notFoundIfNullish } from "~/utils/remix.server"; import { CALENDAR_PAGE } from "~/utils/urls"; import { actualNumber, id } from "~/utils/zod"; import { canDeleteCalendarEvent } from "../calendar-utils"; @@ -19,7 +19,7 @@ export const action: ActionFunction = async ({ params }) => { const parsedParams = z .object({ id: z.preprocess(actualNumber, id) }) .parse(params); - const event = notFoundIfFalsy( + const event = notFoundIfNullish( await CalendarRepository.findById(parsedParams.id), ); diff --git a/app/features/calendar/loaders/calendar.$id.report-winners.server.ts b/app/features/calendar/loaders/calendar.$id.report-winners.server.ts index 1d16482e7..13e479471 100644 --- a/app/features/calendar/loaders/calendar.$id.report-winners.server.ts +++ b/app/features/calendar/loaders/calendar.$id.report-winners.server.ts @@ -2,7 +2,7 @@ import type { LoaderFunctionArgs } from "react-router"; import { requireUser } from "~/features/auth/core/user.server"; import * as CalendarRepository from "~/features/calendar/CalendarRepository.server"; import { - notFoundIfFalsy, + notFoundIfNullish, parseParams, unauthorizedIfFalsy, } from "~/utils/remix.server"; @@ -15,7 +15,7 @@ export const loader = async (args: LoaderFunctionArgs) => { schema: idObject, }); const user = requireUser(); - const event = notFoundIfFalsy(await CalendarRepository.findById(params.id)); + const event = notFoundIfNullish(await CalendarRepository.findById(params.id)); unauthorizedIfFalsy( canReportCalendarEventWinners({ diff --git a/app/features/calendar/loaders/calendar.$id.server.ts b/app/features/calendar/loaders/calendar.$id.server.ts index a40029f8a..dccd9d423 100644 --- a/app/features/calendar/loaders/calendar.$id.server.ts +++ b/app/features/calendar/loaders/calendar.$id.server.ts @@ -1,7 +1,7 @@ import type { LoaderFunctionArgs } from "react-router"; import { redirect } from "react-router"; import * as CalendarRepository from "~/features/calendar/CalendarRepository.server"; -import { notFoundIfFalsy, parseParams } from "~/utils/remix.server"; +import { notFoundIfNullish, parseParams } from "~/utils/remix.server"; import { tournamentPage } from "~/utils/urls"; import { idObject } from "~/utils/zod"; @@ -10,7 +10,7 @@ export const loader = async (args: LoaderFunctionArgs) => { params: args.params, schema: idObject, }); - const event = notFoundIfFalsy( + const event = notFoundIfNullish( await CalendarRepository.findById(params.id, { includeBadgePrizes: true, includeMapPool: true, diff --git a/app/features/scrims/actions/scrims.$id.server.ts b/app/features/scrims/actions/scrims.$id.server.ts index 17fa58291..bd1aa7e26 100644 --- a/app/features/scrims/actions/scrims.$id.server.ts +++ b/app/features/scrims/actions/scrims.$id.server.ts @@ -5,7 +5,7 @@ import { requirePermission } from "~/modules/permissions/guards.server"; import { errorToast, errorToastIfFalsy, - notFoundIfFalsy, + notFoundIfNullish, parseParams, parseRequestPayload, } from "~/utils/remix.server"; @@ -23,7 +23,7 @@ import { parseMapPoolInput } from "../scrims-utils"; export const action = async ({ request, params }: ActionFunctionArgs) => { const { id } = parseParams({ params, schema: idObject }); - const post = notFoundIfFalsy(await ScrimPostRepository.findById(id)); + const post = notFoundIfNullish(await ScrimPostRepository.findById(id)); const user = requireUser(); const data = await parseRequestPayload({ diff --git a/app/features/scrims/loaders/scrims.$id.server.ts b/app/features/scrims/loaders/scrims.$id.server.ts index 71357bbeb..1cea2293a 100644 --- a/app/features/scrims/loaders/scrims.$id.server.ts +++ b/app/features/scrims/loaders/scrims.$id.server.ts @@ -3,7 +3,7 @@ import { chatAccessible } from "~/features/chat/chat-utils"; import * as UserCardRepository from "~/features/user-card/UserCardRepository.server"; import * as UserRepository from "~/features/user-page/UserRepository.server"; import { databaseTimestampToDate } from "~/utils/dates"; -import { notFoundIfFalsy } from "../../../utils/remix.server"; +import { notFoundIfNullish } from "../../../utils/remix.server"; import { type AuthenticatedUser, requireUser, @@ -17,7 +17,7 @@ import * as ScrimPostRepository from "../ScrimPostRepository.server"; export const loader = async ({ params }: LoaderFunctionArgs) => { const user = requireUser(); - const post = notFoundIfFalsy( + const post = notFoundIfNullish( await ScrimPostRepository.findById(Number(params.id)), ); diff --git a/app/features/sendouq-match/actions/q.match.$id.server.ts b/app/features/sendouq-match/actions/q.match.$id.server.ts index 177359dfa..b8234c36d 100644 --- a/app/features/sendouq-match/actions/q.match.$id.server.ts +++ b/app/features/sendouq-match/actions/q.match.$id.server.ts @@ -19,7 +19,7 @@ import { logger } from "~/utils/logger"; import { errorToast, errorToastIfFalsy, - notFoundIfFalsy, + notFoundIfNullish, parseParams, parseRequestPayload, } from "~/utils/remix.server"; @@ -39,7 +39,7 @@ export const action = async ({ request, params }: ActionFunctionArgs) => { schema: matchSchema, }); - const match = notFoundIfFalsy(await SQMatchRepository.findById(matchId)); + const match = notFoundIfNullish(await SQMatchRepository.findById(matchId)); const isStaff = user.roles.includes("STAFF"); const isParticipant = [ ...match.groupAlpha.members, diff --git a/app/features/sendouq-match/loaders/q.match.$id.server.ts b/app/features/sendouq-match/loaders/q.match.$id.server.ts index f4b379df7..417322dee 100644 --- a/app/features/sendouq-match/loaders/q.match.$id.server.ts +++ b/app/features/sendouq-match/loaders/q.match.$id.server.ts @@ -8,7 +8,7 @@ import * as SQMatchRepository from "~/features/sendouq-match/SQMatchRepository.s import * as UserCardRepository from "~/features/user-card/UserCardRepository.server"; import { databaseTimestampToDate } from "~/utils/dates"; import type { SerializeFrom } from "~/utils/remix"; -import { notFoundIfFalsy, parseParams } from "~/utils/remix.server"; +import { notFoundIfNullish, parseParams } from "~/utils/remix.server"; import { qMatchPageParamsSchema } from "../q-match-schemas"; export const loader = async ({ params }: LoaderFunctionArgs) => { @@ -18,7 +18,7 @@ export const loader = async ({ params }: LoaderFunctionArgs) => { schema: qMatchPageParamsSchema, }).id; - const matchUnmapped = notFoundIfFalsy( + const matchUnmapped = notFoundIfNullish( await SQMatchRepository.findById(matchId), ); diff --git a/app/features/team/actions/t.$customUrl.edit.server.ts b/app/features/team/actions/t.$customUrl.edit.server.ts index 899729752..9c6617e34 100644 --- a/app/features/team/actions/t.$customUrl.edit.server.ts +++ b/app/features/team/actions/t.$customUrl.edit.server.ts @@ -3,7 +3,7 @@ import { redirect } from "react-router"; import { requireUser } from "~/features/auth/core/user.server"; import { parseFormDataWithImages } from "~/form/parse.server"; import { clampThemeToGamut } from "~/utils/oklch-gamut"; -import { errorToastIfFalsy, notFoundIfFalsy } from "~/utils/remix.server"; +import { errorToastIfFalsy, notFoundIfNullish } from "~/utils/remix.server"; import { assertUnreachable } from "~/utils/types"; import { mySlugify, teamPage } from "~/utils/urls"; import * as TeamRepository from "../TeamRepository.server"; @@ -14,7 +14,9 @@ export const action: ActionFunction = async ({ request, params }) => { const user = requireUser(); const { customUrl } = teamParamsSchema.parse(params); - const team = notFoundIfFalsy(await TeamRepository.findByCustomUrl(customUrl)); + const team = notFoundIfNullish( + await TeamRepository.findByCustomUrl(customUrl), + ); errorToastIfFalsy( isTeamManager({ team, user }) || user.roles.includes("ADMIN"), diff --git a/app/features/team/actions/t.$customUrl.index.server.ts b/app/features/team/actions/t.$customUrl.index.server.ts index a34029d0b..639a66de1 100644 --- a/app/features/team/actions/t.$customUrl.index.server.ts +++ b/app/features/team/actions/t.$customUrl.index.server.ts @@ -3,7 +3,7 @@ import { redirect } from "react-router"; import { requireUser } from "~/features/auth/core/user.server"; import { errorToastIfFalsy, - notFoundIfFalsy, + notFoundIfNullish, parseRequestPayload, } from "~/utils/remix.server"; import { assertUnreachable } from "~/utils/types"; @@ -22,7 +22,9 @@ export const action: ActionFunction = async ({ request, params }) => { }); const { customUrl } = teamParamsSchema.parse(params); - const team = notFoundIfFalsy(await TeamRepository.findByCustomUrl(customUrl)); + const team = notFoundIfNullish( + await TeamRepository.findByCustomUrl(customUrl), + ); switch (data._action) { case "LEAVE_TEAM": { diff --git a/app/features/team/actions/t.$customUrl.join.server.ts b/app/features/team/actions/t.$customUrl.join.server.ts index 6caf50440..5a34452d7 100644 --- a/app/features/team/actions/t.$customUrl.join.server.ts +++ b/app/features/team/actions/t.$customUrl.join.server.ts @@ -1,6 +1,6 @@ import { type ActionFunction, redirect } from "react-router"; import { requireUser } from "~/features/auth/core/user.server"; -import { errorToastIfFalsy, notFoundIfFalsy } from "~/utils/remix.server"; +import { errorToastIfFalsy, notFoundIfNullish } from "~/utils/remix.server"; import { teamPage } from "~/utils/urls"; import { validateInviteCode } from "../loaders/t.$customUrl.join.server"; import * as TeamRepository from "../TeamRepository.server"; @@ -11,7 +11,7 @@ export const action: ActionFunction = async ({ params, url }) => { const user = requireUser(); const { customUrl } = teamParamsSchema.parse(params); - const team = notFoundIfFalsy( + const team = notFoundIfNullish( await TeamRepository.findByCustomUrl(customUrl, { includeInviteCode: true, }), diff --git a/app/features/team/actions/t.$customUrl.roster.server.ts b/app/features/team/actions/t.$customUrl.roster.server.ts index 167f4a9ee..7473d21a8 100644 --- a/app/features/team/actions/t.$customUrl.roster.server.ts +++ b/app/features/team/actions/t.$customUrl.roster.server.ts @@ -3,7 +3,7 @@ import { redirect } from "react-router"; import type { MemberRole, MemberRoleType } from "~/db/tables"; import { requireUser } from "~/features/auth/core/user.server"; import { parseFormData } from "~/form/parse.server"; -import { errorToastIfFalsy, notFoundIfFalsy } from "~/utils/remix.server"; +import { errorToastIfFalsy, notFoundIfNullish } from "~/utils/remix.server"; import { assertUnreachable } from "~/utils/types"; import { teamPage } from "~/utils/urls"; import * as TeamRepository from "../TeamRepository.server"; @@ -15,7 +15,9 @@ export const action: ActionFunction = async ({ request, params }) => { const user = requireUser(); const { customUrl } = teamParamsSchema.parse(params); - const team = notFoundIfFalsy(await TeamRepository.findByCustomUrl(customUrl)); + const team = notFoundIfNullish( + await TeamRepository.findByCustomUrl(customUrl), + ); errorToastIfFalsy( isTeamManager({ team, user }) || user.roles.includes("ADMIN"), "Only team manager or owner can manage roster", diff --git a/app/features/team/loaders/t.$customUrl.edit.server.ts b/app/features/team/loaders/t.$customUrl.edit.server.ts index da88821af..6eb434022 100644 --- a/app/features/team/loaders/t.$customUrl.edit.server.ts +++ b/app/features/team/loaders/t.$customUrl.edit.server.ts @@ -1,7 +1,7 @@ import type { LoaderFunctionArgs } from "react-router"; import { redirect } from "react-router"; import { requireUser } from "~/features/auth/core/user.server"; -import { notFoundIfFalsy } from "~/utils/remix.server"; +import { notFoundIfNullish } from "~/utils/remix.server"; import { teamPage } from "~/utils/urls"; import * as TeamRepository from "../TeamRepository.server"; import { teamParamsSchema } from "../team-schemas.server"; @@ -11,7 +11,7 @@ export const loader = async ({ params }: LoaderFunctionArgs) => { const user = requireUser(); const { customUrl } = teamParamsSchema.parse(params); - const team = notFoundIfFalsy( + const team = notFoundIfNullish( await TeamRepository.findByCustomUrl(customUrl, { includeUnvalidatedImages: true, }), diff --git a/app/features/team/loaders/t.$customUrl.join.server.ts b/app/features/team/loaders/t.$customUrl.join.server.ts index afdc62d70..fa1f1ec50 100644 --- a/app/features/team/loaders/t.$customUrl.join.server.ts +++ b/app/features/team/loaders/t.$customUrl.join.server.ts @@ -2,7 +2,7 @@ import type { LoaderFunctionArgs } from "react-router"; import { redirect } from "react-router"; import { requireUser } from "~/features/auth/core/user.server"; import { SHORT_NANOID_LENGTH } from "~/utils/id"; -import { notFoundIfFalsy } from "~/utils/remix.server"; +import { notFoundIfNullish } from "~/utils/remix.server"; import { teamPage } from "~/utils/urls"; import * as TeamRepository from "../TeamRepository.server"; import { TEAM } from "../team-constants"; @@ -13,7 +13,7 @@ export const loader = async ({ params, url }: LoaderFunctionArgs) => { const user = requireUser(); const { customUrl } = teamParamsSchema.parse(params); - const team = notFoundIfFalsy( + const team = notFoundIfNullish( await TeamRepository.findByCustomUrl(customUrl, { includeInviteCode: true, }), diff --git a/app/features/team/loaders/t.$customUrl.results.server.ts b/app/features/team/loaders/t.$customUrl.results.server.ts index c34b16be5..9ec8bbf90 100644 --- a/app/features/team/loaders/t.$customUrl.results.server.ts +++ b/app/features/team/loaders/t.$customUrl.results.server.ts @@ -1,6 +1,6 @@ import type { LoaderFunctionArgs } from "react-router"; import type { SerializeFrom } from "~/utils/remix"; -import { notFoundIfFalsy } from "~/utils/remix.server"; +import { notFoundIfNullish } from "~/utils/remix.server"; import * as TeamRepository from "../TeamRepository.server"; import { teamParamsSchema } from "../team-schemas.server"; @@ -9,7 +9,9 @@ export type TeamResultsLoaderData = SerializeFrom; export const loader = async ({ params }: LoaderFunctionArgs) => { const { customUrl } = teamParamsSchema.parse(params); - const team = notFoundIfFalsy(await TeamRepository.findByCustomUrl(customUrl)); + const team = notFoundIfNullish( + await TeamRepository.findByCustomUrl(customUrl), + ); const results = await TeamRepository.findResultsById(team.id); diff --git a/app/features/team/loaders/t.$customUrl.roster.server.ts b/app/features/team/loaders/t.$customUrl.roster.server.ts index 5a2e7005e..c4883d528 100644 --- a/app/features/team/loaders/t.$customUrl.roster.server.ts +++ b/app/features/team/loaders/t.$customUrl.roster.server.ts @@ -1,7 +1,7 @@ import type { LoaderFunctionArgs } from "react-router"; import { redirect } from "react-router"; import { requireUser } from "~/features/auth/core/user.server"; -import { notFoundIfFalsy } from "~/utils/remix.server"; +import { notFoundIfNullish } from "~/utils/remix.server"; import { teamPage } from "~/utils/urls"; import * as TeamRepository from "../TeamRepository.server"; import { teamParamsSchema } from "../team-schemas.server"; @@ -11,7 +11,7 @@ export const loader = async ({ params }: LoaderFunctionArgs) => { const user = requireUser(); const { customUrl } = teamParamsSchema.parse(params); - const team = notFoundIfFalsy( + const team = notFoundIfNullish( await TeamRepository.findByCustomUrl(customUrl, { includeInviteCode: true, }), diff --git a/app/features/team/loaders/t.$customUrl.server.ts b/app/features/team/loaders/t.$customUrl.server.ts index 3496371f8..202cb39fe 100644 --- a/app/features/team/loaders/t.$customUrl.server.ts +++ b/app/features/team/loaders/t.$customUrl.server.ts @@ -1,6 +1,6 @@ import type { LoaderFunctionArgs } from "react-router"; import type { SerializeFrom } from "~/utils/remix"; -import { notFoundIfFalsy } from "~/utils/remix.server"; +import { notFoundIfNullish } from "~/utils/remix.server"; import * as TeamRepository from "../TeamRepository.server"; import { teamParamsSchema } from "../team-schemas.server"; import { canAddCustomizedColors } from "../team-utils"; @@ -10,7 +10,9 @@ export type TeamLoaderData = SerializeFrom; export const loader = async ({ params }: LoaderFunctionArgs) => { const { customUrl } = teamParamsSchema.parse(params); - const team = notFoundIfFalsy(await TeamRepository.findByCustomUrl(customUrl)); + const team = notFoundIfNullish( + await TeamRepository.findByCustomUrl(customUrl), + ); const results = await TeamRepository.findResultPlacementsById(team.id); diff --git a/app/features/top-search/actions/xsearch.player.$id.server.ts b/app/features/top-search/actions/xsearch.player.$id.server.ts index e9f3946c9..5845ef91e 100644 --- a/app/features/top-search/actions/xsearch.player.$id.server.ts +++ b/app/features/top-search/actions/xsearch.player.$id.server.ts @@ -4,7 +4,7 @@ import * as BadgeRepository from "~/features/badges/BadgeRepository.server"; import { logger } from "~/utils/logger"; import { errorToastIfFalsy, - notFoundIfFalsy, + notFoundIfNullish, parseParams, successToast, } from "~/utils/remix.server"; @@ -18,7 +18,7 @@ export const action = async ({ params }: ActionFunctionArgs) => { schema: idObject, }); - const placements = notFoundIfFalsy( + const placements = notFoundIfNullish( await XRankPlacementRepository.findPlacementsByPlayerId(id), ); const currentLinkedUserDiscordId = placements[0].discordId; diff --git a/app/features/top-search/loaders/xsearch.player.$id.server.ts b/app/features/top-search/loaders/xsearch.player.$id.server.ts index aad4a2e0b..cfd3a794b 100644 --- a/app/features/top-search/loaders/xsearch.player.$id.server.ts +++ b/app/features/top-search/loaders/xsearch.player.$id.server.ts @@ -1,6 +1,6 @@ import type { LoaderFunctionArgs } from "react-router"; import * as R from "remeda"; -import { notFoundIfFalsy, parseParams } from "~/utils/remix.server"; +import { notFoundIfNullish, parseParams } from "~/utils/remix.server"; import { idObject } from "~/utils/zod"; import * as XRankPlacementRepository from "../XRankPlacementRepository.server"; @@ -10,7 +10,7 @@ export const loader = async (args: LoaderFunctionArgs) => { schema: idObject, }); - const placements = notFoundIfFalsy( + const placements = notFoundIfNullish( await XRankPlacementRepository.findPlacementsByPlayerId(params.id), ); diff --git a/app/features/tournament-bracket/core/Tournament.server.ts b/app/features/tournament-bracket/core/Tournament.server.ts index ce92a69d8..8bce636c0 100644 --- a/app/features/tournament-bracket/core/Tournament.server.ts +++ b/app/features/tournament-bracket/core/Tournament.server.ts @@ -6,7 +6,7 @@ import { getTentativeTier } from "~/features/tournament-organization/core/tentat import type { TournamentManagerDataSet } from "~/modules/brackets-manager/types"; import { isAdmin } from "~/modules/permissions/utils"; import { databaseTimestampToDate } from "~/utils/dates"; -import { notFoundIfFalsy } from "~/utils/remix.server"; +import { notFoundIfNullish } from "~/utils/remix.server"; import type { Unwrapped } from "~/utils/types"; import { getServerTournamentManager } from "./brackets-manager/manager.server"; import { RunningTournaments } from "./RunningTournaments.server"; @@ -91,7 +91,7 @@ export async function tournamentFromDB(args: { user: { id: number } | undefined; tournamentId: number; }) { - const data = notFoundIfFalsy(await tournamentData(args)); + const data = notFoundIfNullish(await tournamentData(args)); const tournament = new Tournament({ ...data, simulateBrackets: false }); syncTournamentToRegistry(tournament); @@ -103,7 +103,7 @@ export async function tournamentFromDBCached(args: { user: { id: number } | undefined; tournamentId: number; }) { - const data = notFoundIfFalsy(await tournamentDataCached(args)); + const data = notFoundIfNullish(await tournamentDataCached(args)); return new Tournament({ ...data, simulateBrackets: false }); } @@ -122,14 +122,14 @@ export async function tournamentDataCached({ tournamentId: number; }) { if (ServerConfig.disableCache) { - return notFoundIfFalsy(await tournamentData({ user, tournamentId })); + return notFoundIfNullish(await tournamentData({ user, tournamentId })); } if (!tournamentDataCache.has(tournamentId)) { tournamentDataCache.set(tournamentId, combinedTournamentData(tournamentId)); } - const data = notFoundIfFalsy(await tournamentDataCache.get(tournamentId)); + const data = notFoundIfNullish(await tournamentDataCache.get(tournamentId)); return dataMapped({ user, ...data }); } diff --git a/app/features/tournament-bracket/loaders/to.$id.divisions.server.ts b/app/features/tournament-bracket/loaders/to.$id.divisions.server.ts index 7a5c8073f..9630045a3 100644 --- a/app/features/tournament-bracket/loaders/to.$id.divisions.server.ts +++ b/app/features/tournament-bracket/loaders/to.$id.divisions.server.ts @@ -1,7 +1,7 @@ import type { LoaderFunctionArgs } from "react-router"; import { getUser } from "~/features/auth/core/user.server"; import * as TournamentRepository from "~/features/tournament/TournamentRepository.server"; -import { notFoundIfFalsy, parseParams } from "~/utils/remix.server"; +import { notFoundIfNullish, parseParams } from "~/utils/remix.server"; import { idObject } from "~/utils/zod"; import type { Unwrapped } from "../../../utils/types"; import { tournamentFromDB } from "../core/Tournament.server"; @@ -13,7 +13,7 @@ export const loader = async ({ params }: LoaderFunctionArgs) => { schema: idObject, }); - const divisions = notFoundIfFalsy(await divisionsCached(tournamentId)); + const divisions = notFoundIfNullish(await divisionsCached(tournamentId)); return { divisions, diff --git a/app/features/tournament-match/actions/to.$id.matches.$mid.server.ts b/app/features/tournament-match/actions/to.$id.matches.$mid.server.ts index 06c5b70d4..944836ed4 100644 --- a/app/features/tournament-match/actions/to.$id.matches.$mid.server.ts +++ b/app/features/tournament-match/actions/to.$id.matches.$mid.server.ts @@ -29,7 +29,7 @@ import invariant from "~/utils/invariant"; import { logger } from "~/utils/logger"; import { errorToastIfFalsy, - notFoundIfFalsy, + notFoundIfNullish, parseParams, parseRequestPayload, } from "~/utils/remix.server"; @@ -57,7 +57,7 @@ export const action: ActionFunction = async ({ params, request }) => { params, schema: matchPageParamsSchema, }); - const match = notFoundIfFalsy( + const match = notFoundIfNullish( await TournamentMatchRepository.findMatchById(matchId), ); diff --git a/app/features/tournament-match/loaders/to.$id.matches.$mid.server.ts b/app/features/tournament-match/loaders/to.$id.matches.$mid.server.ts index c94ae4db0..d618f6a79 100644 --- a/app/features/tournament-match/loaders/to.$id.matches.$mid.server.ts +++ b/app/features/tournament-match/loaders/to.$id.matches.$mid.server.ts @@ -18,7 +18,7 @@ import { cache, IN_MILLISECONDS, ttl } from "~/utils/cache.server"; import { IS_E2E_TEST_RUN } from "~/utils/e2e"; import { logger } from "~/utils/logger"; import type { SerializeFrom } from "~/utils/remix"; -import { notFoundIfFalsy, parseParams } from "~/utils/remix.server"; +import { notFoundIfNullish, parseParams } from "~/utils/remix.server"; import { tournamentMatchPage } from "~/utils/urls"; import { executeRoll } from "../core/executeRoll.server"; import { mapListFromResults, resolveMapList } from "../core/mapList.server"; @@ -38,7 +38,7 @@ export const loader = async ({ params }: LoaderFunctionArgs) => { user: undefined, }); - const match = notFoundIfFalsy( + const match = notFoundIfNullish( await TournamentMatchRepository.findMatchById(matchId), ); diff --git a/app/features/tournament-organization/tournament-organization-utils.server.ts b/app/features/tournament-organization/tournament-organization-utils.server.ts index 7d109e69c..e2f0a4a38 100644 --- a/app/features/tournament-organization/tournament-organization-utils.server.ts +++ b/app/features/tournament-organization/tournament-organization-utils.server.ts @@ -1,6 +1,6 @@ import type { LoaderFunctionArgs } from "react-router"; import { z } from "zod"; -import { notFoundIfFalsy, parseParams } from "~/utils/remix.server"; +import { notFoundIfNullish, parseParams } from "~/utils/remix.server"; import * as TournamentOrganizationRepository from "./TournamentOrganizationRepository.server"; const organizationParamsSchema = z.object({ @@ -11,7 +11,7 @@ export async function organizationFromParams( params: LoaderFunctionArgs["params"], ) { const { slug } = parseParams({ params, schema: organizationParamsSchema }); - return notFoundIfFalsy( + return notFoundIfNullish( await TournamentOrganizationRepository.findBySlug(slug), ); } diff --git a/app/features/tournament/actions/to.$id.join.server.ts b/app/features/tournament/actions/to.$id.join.server.ts index cb3638818..fb85d07e5 100644 --- a/app/features/tournament/actions/to.$id.join.server.ts +++ b/app/features/tournament/actions/to.$id.join.server.ts @@ -12,7 +12,7 @@ import * as UserRepository from "~/features/user-page/UserRepository.server"; import invariant from "~/utils/invariant"; import { errorToastIfFalsy, - notFoundIfFalsy, + notFoundIfNullish, parseParams, } from "~/utils/remix.server"; import { tournamentPage, tournamentRegisterPage } from "~/utils/urls"; @@ -32,7 +32,7 @@ export const action: ActionFunction = async ({ params, url }) => { const inviteCode = url.searchParams.get("code"); invariant(inviteCode, "code is missing"); - const leanTeam = notFoundIfFalsy( + const leanTeam = notFoundIfNullish( await TournamentTeamRepository.findByInviteCode(inviteCode), ); diff --git a/app/features/tournament/routes/luti.ts b/app/features/tournament/routes/luti.ts index 0d7d89404..f99ff980a 100644 --- a/app/features/tournament/routes/luti.ts +++ b/app/features/tournament/routes/luti.ts @@ -1,12 +1,12 @@ import { redirect } from "react-router"; -import { notFoundIfFalsy } from "../../../utils/remix.server"; +import { notFoundIfNullish } from "~/utils/remix.server"; import { tournamentPage } from "../../../utils/urls"; import { LEAGUES } from "../tournament-constants"; const maybeLatest = LEAGUES.LUTI?.at(-1); export const loader = () => { - const latest = notFoundIfFalsy(maybeLatest); + const latest = notFoundIfNullish(maybeLatest); return redirect(tournamentPage(latest.tournamentId)); }; diff --git a/app/features/user-page/actions/u.$identifier.admin.server.ts b/app/features/user-page/actions/u.$identifier.admin.server.ts index 2452b880a..2c01e4caf 100644 --- a/app/features/user-page/actions/u.$identifier.admin.server.ts +++ b/app/features/user-page/actions/u.$identifier.admin.server.ts @@ -6,7 +6,7 @@ import { adminTabActionSchema } from "~/features/user-page/user-page-schemas"; import { requireRole } from "~/modules/permissions/guards.server"; import { badRequestIfFalsy, - notFoundIfFalsy, + notFoundIfNullish, parseRequestPayload, } from "~/utils/remix.server"; import { assertUnreachable } from "~/utils/types"; @@ -21,7 +21,7 @@ export const action = async ({ request, params }: ActionFunctionArgs) => { schema: adminTabActionSchema, }); - const user = notFoundIfFalsy( + const user = notFoundIfNullish( await UserRepository.findLayoutDataByIdentifier(params.identifier!), ); diff --git a/app/features/user-page/loaders/u.$identifier.admin.server.ts b/app/features/user-page/loaders/u.$identifier.admin.server.ts index b08c1819a..2010a2dd0 100644 --- a/app/features/user-page/loaders/u.$identifier.admin.server.ts +++ b/app/features/user-page/loaders/u.$identifier.admin.server.ts @@ -6,7 +6,7 @@ import * as UserReportRepository from "~/features/user-report/UserReportReposito import { requireRole } from "~/modules/permissions/guards.server"; import { databaseTimestampToDate } from "~/utils/dates"; import { logger } from "~/utils/logger"; -import { notFoundIfFalsy } from "~/utils/remix.server"; +import { notFoundIfNullish } from "~/utils/remix.server"; import { convertSnowflakeToDate } from "~/utils/users"; const REPORT_GRAPH_MONTHS = 12; @@ -16,7 +16,7 @@ export const loader = async ({ params }: LoaderFunctionArgs) => { requireRole("STAFF"); - const user = notFoundIfFalsy( + const user = notFoundIfNullish( await UserRepository.findLayoutDataByIdentifier(params.identifier!), ); @@ -24,7 +24,7 @@ export const loader = async ({ params }: LoaderFunctionArgs) => { `User ${loggedInUser.username} (#${loggedInUser.id}) is viewing admin tab for user ${user.username} (#${user.id})`, ); - const userData = notFoundIfFalsy( + const userData = notFoundIfNullish( await UserRepository.findModInfoById(user.id), ); diff --git a/app/features/user-page/loaders/u.$identifier.art.server.ts b/app/features/user-page/loaders/u.$identifier.art.server.ts index 9baf97281..f9097a778 100644 --- a/app/features/user-page/loaders/u.$identifier.art.server.ts +++ b/app/features/user-page/loaders/u.$identifier.art.server.ts @@ -3,14 +3,14 @@ import * as ArtRepository from "~/features/art/ArtRepository.server"; import { getUser } from "~/features/auth/core/user.server"; import * as ImageRepository from "~/features/img-upload/ImageRepository.server"; import * as UserRepository from "~/features/user-page/UserRepository.server"; -import { notFoundIfFalsy } from "~/utils/remix.server"; +import { notFoundIfNullish } from "~/utils/remix.server"; import { userParamsSchema } from "../user-page-schemas"; export const loader = async ({ params }: LoaderFunctionArgs) => { const loggedInUser = getUser(); const { identifier } = userParamsSchema.parse(params); - const user = notFoundIfFalsy( + const user = notFoundIfNullish( await UserRepository.identifierToUserId(identifier), ); diff --git a/app/features/user-page/loaders/u.$identifier.builds.server.ts b/app/features/user-page/loaders/u.$identifier.builds.server.ts index 4c4ea0c97..da55bcc2e 100644 --- a/app/features/user-page/loaders/u.$identifier.builds.server.ts +++ b/app/features/user-page/loaders/u.$identifier.builds.server.ts @@ -4,7 +4,7 @@ import { getUser } from "~/features/auth/core/user.server"; import * as BuildRepository from "~/features/builds/BuildRepository.server"; import * as UserRepository from "~/features/user-page/UserRepository.server"; import type { SerializeFrom } from "~/utils/remix"; -import { notFoundIfFalsy, privatelyCachedJson } from "~/utils/remix.server"; +import { notFoundIfNullish, privatelyCachedJson } from "~/utils/remix.server"; import { sortBuilds } from "../core/build-sorting.server"; import { userParamsSchema } from "../user-page-schemas"; @@ -13,7 +13,7 @@ export type UserBuildsPageData = SerializeFrom; export const loader = async ({ params }: LoaderFunctionArgs) => { const loggedInUser = getUser(); const { identifier } = userParamsSchema.parse(params); - const user = notFoundIfFalsy( + const user = notFoundIfNullish( await UserRepository.identifierToBuildFields(identifier), ); diff --git a/app/features/user-page/loaders/u.$identifier.edit.server.ts b/app/features/user-page/loaders/u.$identifier.edit.server.ts index b2fd03fcb..e8fba8f59 100644 --- a/app/features/user-page/loaders/u.$identifier.edit.server.ts +++ b/app/features/user-page/loaders/u.$identifier.edit.server.ts @@ -1,14 +1,14 @@ import { type LoaderFunctionArgs, redirect } from "react-router"; import { requireUser } from "~/features/auth/core/user.server"; import * as UserRepository from "~/features/user-page/UserRepository.server"; -import { notFoundIfFalsy } from "~/utils/remix.server"; +import { notFoundIfNullish } from "~/utils/remix.server"; import { userPage } from "~/utils/urls"; import { userParamsSchema } from "../user-page-schemas"; export const loader = async ({ params }: LoaderFunctionArgs) => { const user = requireUser(); const { identifier } = userParamsSchema.parse(params); - const userToBeEdited = notFoundIfFalsy( + const userToBeEdited = notFoundIfNullish( await UserRepository.findLayoutDataByIdentifier(identifier), ); if (user.id !== userToBeEdited.id) { diff --git a/app/features/user-page/loaders/u.$identifier.index.server.ts b/app/features/user-page/loaders/u.$identifier.index.server.ts index 50cb71500..601ba7f74 100644 --- a/app/features/user-page/loaders/u.$identifier.index.server.ts +++ b/app/features/user-page/loaders/u.$identifier.index.server.ts @@ -1,10 +1,10 @@ import type { LoaderFunctionArgs } from "react-router"; import * as UserCardRepository from "~/features/user-card/UserCardRepository.server"; import * as UserRepository from "~/features/user-page/UserRepository.server"; -import { notFoundIfFalsy } from "~/utils/remix.server"; +import { notFoundIfNullish } from "~/utils/remix.server"; export const loader = async ({ params }: LoaderFunctionArgs) => { - const { id: userId } = notFoundIfFalsy( + const { id: userId } = notFoundIfNullish( await UserRepository.identifierToUserId(params.identifier!), ); @@ -17,14 +17,14 @@ export const loader = async ({ params }: LoaderFunctionArgs) => { if (widgetsEnabled) { return { type: "new" as const, - widgets: notFoundIfFalsy( + widgets: notFoundIfNullish( await UserRepository.widgetsByUserId(params.identifier!), ), ...userCards, }; } - const user = notFoundIfFalsy( + const user = notFoundIfNullish( await UserRepository.findProfileByIdentifier(params.identifier!), ); diff --git a/app/features/user-page/loaders/u.$identifier.results.server.ts b/app/features/user-page/loaders/u.$identifier.results.server.ts index cbe41dd35..fb27426de 100644 --- a/app/features/user-page/loaders/u.$identifier.results.server.ts +++ b/app/features/user-page/loaders/u.$identifier.results.server.ts @@ -3,7 +3,7 @@ import { getUser } from "~/features/auth/core/user.server"; import * as UserRepository from "~/features/user-page/UserRepository.server"; import type { SerializeFrom } from "~/utils/remix"; import { - notFoundIfFalsy, + notFoundIfNullish, parseSafeSearchParams, redirectIfPageOutOfBounds, } from "~/utils/remix.server"; @@ -21,7 +21,7 @@ export const loader = async ({ params, request, url }: LoaderFunctionArgs) => { schema: userResultsPageSearchParamsSchema, }); - const userId = notFoundIfFalsy( + const userId = notFoundIfNullish( await UserRepository.identifierToUserId(params.identifier!), ).id; const hasHighlightedResults = diff --git a/app/features/user-page/loaders/u.$identifier.seasons.index.server.ts b/app/features/user-page/loaders/u.$identifier.seasons.index.server.ts index 7a86fbcd0..dd59b3c98 100644 --- a/app/features/user-page/loaders/u.$identifier.seasons.index.server.ts +++ b/app/features/user-page/loaders/u.$identifier.seasons.index.server.ts @@ -4,7 +4,7 @@ import * as LeaderboardRepository from "~/features/leaderboards/LeaderboardRepos import * as SQMatchRepository from "~/features/sendouq-match/SQMatchRepository.server"; import * as UserRepository from "~/features/user-page/UserRepository.server"; import type { SerializeFrom } from "~/utils/remix"; -import { notFoundIfFalsy } from "~/utils/remix.server"; +import { notFoundIfNullish } from "~/utils/remix.server"; import { seasonsSearchParamsSchema, userParamsSchema, @@ -21,7 +21,7 @@ export const loader = async ({ params, url }: LoaderFunctionArgs) => { Object.fromEntries(url.searchParams), ); - const user = notFoundIfFalsy( + const user = notFoundIfNullish( await UserRepository.identifierToUserId(identifier), ); const seasonsParticipatedIn = diff --git a/app/features/user-page/loaders/u.$identifier.seasons.server.ts b/app/features/user-page/loaders/u.$identifier.seasons.server.ts index df0088c5d..856c44b3c 100644 --- a/app/features/user-page/loaders/u.$identifier.seasons.server.ts +++ b/app/features/user-page/loaders/u.$identifier.seasons.server.ts @@ -7,7 +7,7 @@ import * as PlayerStatRepository from "~/features/sendouq-match/PlayerStatReposi import * as SQMatchRepository from "~/features/sendouq-match/SQMatchRepository.server"; import * as UserRepository from "~/features/user-page/UserRepository.server"; import type { SerializeFrom } from "~/utils/remix"; -import { notFoundIfFalsy } from "~/utils/remix.server"; +import { notFoundIfNullish } from "~/utils/remix.server"; import { seasonsSearchParamsSchema, userParamsSchema, @@ -24,7 +24,7 @@ export const loader = async ({ params, url }: LoaderFunctionArgs) => { Object.fromEntries(url.searchParams), ); - const user = notFoundIfFalsy( + const user = notFoundIfNullish( await UserRepository.identifierToUserId(identifier), ); const seasonsParticipatedIn = diff --git a/app/features/user-page/loaders/u.$identifier.seasons.stats.server.ts b/app/features/user-page/loaders/u.$identifier.seasons.stats.server.ts index 10f11d8e2..f48b5449b 100644 --- a/app/features/user-page/loaders/u.$identifier.seasons.stats.server.ts +++ b/app/features/user-page/loaders/u.$identifier.seasons.stats.server.ts @@ -5,7 +5,7 @@ import * as PlayerStatRepository from "~/features/sendouq-match/PlayerStatReposi import * as ReportedWeaponRepository from "~/features/sendouq-match/ReportedWeaponRepository.server"; import * as UserRepository from "~/features/user-page/UserRepository.server"; import type { SerializeFrom } from "~/utils/remix"; -import { notFoundIfFalsy } from "~/utils/remix.server"; +import { notFoundIfNullish } from "~/utils/remix.server"; import { seasonsSearchParamsSchema, userParamsSchema, @@ -22,7 +22,7 @@ export const loader = async ({ params, url }: LoaderFunctionArgs) => { Object.fromEntries(url.searchParams), ); - const user = notFoundIfFalsy( + const user = notFoundIfNullish( await UserRepository.identifierToUserId(identifier), ); const seasonsParticipatedIn = diff --git a/app/features/user-page/loaders/u.$identifier.server.ts b/app/features/user-page/loaders/u.$identifier.server.ts index 876aec9a0..2eb0325f1 100644 --- a/app/features/user-page/loaders/u.$identifier.server.ts +++ b/app/features/user-page/loaders/u.$identifier.server.ts @@ -3,14 +3,14 @@ import { getUser } from "~/features/auth/core/user.server"; import * as FriendRepository from "~/features/friends/FriendRepository.server"; import * as UserRepository from "~/features/user-page/UserRepository.server"; import type { SerializeFrom } from "~/utils/remix"; -import { notFoundIfFalsy } from "~/utils/remix.server"; +import { notFoundIfNullish } from "~/utils/remix.server"; export type UserPageLoaderData = SerializeFrom; export const loader = async ({ params }: LoaderFunctionArgs) => { const loggedInUser = getUser(); - const user = notFoundIfFalsy( + const user = notFoundIfNullish( await UserRepository.findLayoutDataByIdentifier( params.identifier!, loggedInUser?.id, diff --git a/app/features/user-page/loaders/u.$identifier.vods.server.ts b/app/features/user-page/loaders/u.$identifier.vods.server.ts index 9f6055bf8..235e8c9dc 100644 --- a/app/features/user-page/loaders/u.$identifier.vods.server.ts +++ b/app/features/user-page/loaders/u.$identifier.vods.server.ts @@ -4,13 +4,13 @@ import * as VodRepository from "~/features/vods/VodRepository.server"; import { VODS_PAGE_BATCH_SIZE } from "~/features/vods/vods-constants"; import { userVodsSearchParamsSchema } from "~/features/vods/vods-schemas"; import { - notFoundIfFalsy, + notFoundIfNullish, parseSearchParams, redirectIfPageOutOfBounds, } from "~/utils/remix.server"; export const loader = async ({ params, request, url }: LoaderFunctionArgs) => { - const userId = notFoundIfFalsy( + const userId = notFoundIfNullish( await UserRepository.identifierToUserId(params.identifier!), ).id; diff --git a/app/features/user-report/routes/user-report.$id.ts b/app/features/user-report/routes/user-report.$id.ts index 05fdd2e1d..e73dbaa86 100644 --- a/app/features/user-report/routes/user-report.$id.ts +++ b/app/features/user-report/routes/user-report.$id.ts @@ -4,7 +4,7 @@ import * as UserRepository from "~/features/user-page/UserRepository.server"; import { parseFormData } from "~/form/parse.server"; import { errorToastIfFalsy, - notFoundIfFalsy, + notFoundIfNullish, parseParams, } from "~/utils/remix.server"; import { sendUserReportWebhook } from "../core/discord-webhook.server"; @@ -22,7 +22,7 @@ export const action = async ({ request, params }: ActionFunctionArgs) => { errorToastIfFalsy(reportedUserId !== user.id, "Can't report yourself"); - const reportedUser = notFoundIfFalsy( + const reportedUser = notFoundIfNullish( await UserRepository.findLeanById(reportedUserId), ); diff --git a/app/features/vods/loaders/vods.$id.server.ts b/app/features/vods/loaders/vods.$id.server.ts index 0914ea36b..533c4a5a4 100644 --- a/app/features/vods/loaders/vods.$id.server.ts +++ b/app/features/vods/loaders/vods.$id.server.ts @@ -1,9 +1,9 @@ import type { LoaderFunctionArgs } from "react-router"; -import { notFoundIfFalsy } from "~/utils/remix.server"; +import { notFoundIfNullish } from "~/utils/remix.server"; import * as VodRepository from "../VodRepository.server"; export const loader = async ({ params }: LoaderFunctionArgs) => { - const vod = notFoundIfFalsy( + const vod = notFoundIfNullish( await VodRepository.findVodById(Number(params.id)), ); diff --git a/app/features/vods/loaders/vods.new.server.ts b/app/features/vods/loaders/vods.new.server.ts index a6714ddf7..8cafffbf9 100644 --- a/app/features/vods/loaders/vods.new.server.ts +++ b/app/features/vods/loaders/vods.new.server.ts @@ -1,7 +1,7 @@ import type { LoaderFunctionArgs } from "react-router"; import { z } from "zod"; import { requireUser } from "~/features/auth/core/user.server"; -import { notFoundIfFalsy } from "~/utils/remix.server"; +import { notFoundIfNullish } from "~/utils/remix.server"; import { actualNumber, id } from "~/utils/zod"; import * as VodRepository from "../VodRepository.server"; import { canEditVideo, vodToVideoBeingAdded } from "../vods-utils"; @@ -21,7 +21,9 @@ export const loader = async ({ url }: LoaderFunctionArgs) => { return { vodToEdit: null }; } - const vod = notFoundIfFalsy(await VodRepository.findVodById(params.data.vod)); + const vod = notFoundIfNullish( + await VodRepository.findVodById(params.data.vod), + ); const vodToEdit = vodToVideoBeingAdded(vod); if ( diff --git a/app/utils/remix.server.ts b/app/utils/remix.server.ts index d6da0282f..fffda62f8 100644 --- a/app/utils/remix.server.ts +++ b/app/utils/remix.server.ts @@ -10,15 +10,10 @@ import { ServerConfig } from "~/config.server"; import { logger } from "./logger"; import { currentRequestPathname } from "./request-context.server"; -export function notFoundIfFalsy(value: T | null | undefined): T { - if (!value) throw new Response(null, { status: 404 }); - - return value; -} - -export function notFoundIfNullLike(value: T | null | undefined): T { - if (value === null || value === undefined) +export function notFoundIfNullish(value: T | null | undefined): T { + if (value === null || value === undefined) { throw new Response(null, { status: 404 }); + } return value; }