100 lines
3.0 KiB
TypeScript
100 lines
3.0 KiB
TypeScript
import { PERMS } from "@/lib/permission-slugs";
|
|
import {
|
|
anyCapability,
|
|
type CanonicalHousekeepingHref,
|
|
type HousekeepingRouteDefinition,
|
|
} from "../../foundation/contracts";
|
|
|
|
export const HOTEL_ROUTE_GROUPS = ["rooms", "navigation", "radio"] as const;
|
|
export type HotelRouteGroup = (typeof HOTEL_ROUTE_GROUPS)[number];
|
|
|
|
export const HOTEL_PRIMARY_ROUTE_IDS = [
|
|
"hotel.rooms",
|
|
"hotel.room-detail",
|
|
"hotel.room-furni",
|
|
"hotel.navigation",
|
|
"hotel.radio.overview",
|
|
"hotel.radio.settings",
|
|
"hotel.radio.monitoring",
|
|
"hotel.radio.moderation",
|
|
"hotel.radio.autodj",
|
|
"hotel.radio.history",
|
|
"hotel.radio.points",
|
|
"hotel.radio.ranks",
|
|
"hotel.radio.api-keys",
|
|
"hotel.radio.banners",
|
|
"hotel.radio.embed",
|
|
] as const;
|
|
export type HotelPrimaryRouteId = (typeof HOTEL_PRIMARY_ROUTE_IDS)[number];
|
|
|
|
function route<const Id extends HotelPrimaryRouteId>(
|
|
id: Id,
|
|
href: CanonicalHousekeepingHref,
|
|
permissions: readonly string[],
|
|
): HousekeepingRouteDefinition & { readonly id: Id } {
|
|
return {
|
|
id,
|
|
href,
|
|
labelKey: `pages.housekeeping.routes.${id}`,
|
|
capability: anyCapability(...permissions),
|
|
};
|
|
}
|
|
|
|
export const HOTEL_PRIMARY_ROUTES = [
|
|
route("hotel.rooms", "/ase/hotel/rooms", [PERMS.ROOMS_VIEW]),
|
|
route("hotel.room-detail", "/ase/hotel/rooms/:id", [
|
|
PERMS.ROOMS_VIEW,
|
|
PERMS.ROOMS_EDIT,
|
|
]),
|
|
route("hotel.room-furni", "/ase/hotel/rooms/:id/furni", [
|
|
PERMS.ROOMS_VIEW,
|
|
PERMS.ROOMS_EDIT,
|
|
]),
|
|
route("hotel.navigation", "/ase/hotel/navigation", [PERMS.PAGES_VIEW]),
|
|
...(
|
|
[
|
|
["hotel.radio.overview", "/ase/hotel/radio/overview"],
|
|
["hotel.radio.settings", "/ase/hotel/radio/settings"],
|
|
["hotel.radio.monitoring", "/ase/hotel/radio/monitoring"],
|
|
["hotel.radio.moderation", "/ase/hotel/radio/moderation"],
|
|
["hotel.radio.autodj", "/ase/hotel/radio/autodj"],
|
|
["hotel.radio.history", "/ase/hotel/radio/history"],
|
|
["hotel.radio.points", "/ase/hotel/radio/points"],
|
|
["hotel.radio.ranks", "/ase/hotel/radio/ranks"],
|
|
["hotel.radio.api-keys", "/ase/hotel/radio/api-keys"],
|
|
["hotel.radio.banners", "/ase/hotel/radio/banners"],
|
|
["hotel.radio.embed", "/ase/hotel/radio/embed"],
|
|
] as const
|
|
).map(([id, href]) => route(id, href, [PERMS.RADIO_VIEW])),
|
|
] as const satisfies readonly HousekeepingRouteDefinition[];
|
|
|
|
const ROUTE_BY_ID = new Map(
|
|
HOTEL_PRIMARY_ROUTES.map((definition) => [definition.id, definition]),
|
|
);
|
|
|
|
export function hotelRouteById(
|
|
id: HotelPrimaryRouteId,
|
|
): HousekeepingRouteDefinition {
|
|
const definition = ROUTE_BY_ID.get(id);
|
|
if (!definition) throw new Error(`unknown Hotel route: ${id}`);
|
|
return definition;
|
|
}
|
|
|
|
export function hotelRouteGroup(id: HotelPrimaryRouteId): HotelRouteGroup {
|
|
if (id === "hotel.navigation") return "navigation";
|
|
return id.startsWith("hotel.radio.") ? "radio" : "rooms";
|
|
}
|
|
|
|
export const HOTEL_ASSET_CANONICAL_ROUTES = Object.freeze([
|
|
Object.freeze({
|
|
legacyPath: "/admin/badges",
|
|
routeId: "economy.rewards.badges",
|
|
href: "/ase/economy/rewards/badges",
|
|
}),
|
|
Object.freeze({
|
|
legacyPath: "/admin/sounds",
|
|
routeId: "economy.rewards.sounds",
|
|
href: "/ase/economy/rewards/sounds",
|
|
}),
|
|
] as const);
|