All files / routes/marketplace room-categories.ts

100% Statements 10/10
100% Branches 0/0
100% Functions 2/2
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38                        1x     1x 13x 13x 13x 13x   13x   11x             11x   2x          
// Room Categories Endpoint - Returns all room categories with cover images and project counts
import { Hono } from "hono";
import { CACHE_KEYS, CACHE_TTL } from "../../lib/cache";
import { handleError, success } from "../../lib/response";
import type { ContextVariables } from "../../middleware";
import { buildRoomCategories } from "./room-categories.shared";
 
type Env = {
	Bindings: CloudflareBindings;
	Variables: ContextVariables;
};
 
const roomCategories = new Hono<Env>();
 
// GET /api/marketplace/room-categories — all room categories with stats
roomCategories.get("/", async (c) => {
	try {
		const dal = c.get("dal");
		const db = c.get("db");
		const cache = c.get("cache");
 
		const data = await cache.getOrSet(
			CACHE_KEYS.MARKETPLACE_ROOM_CATEGORIES,
			() => buildRoomCategories(db, dal),
			{
				l1Ttl: CACHE_TTL.MARKETPLACE_ROOM_CATEGORIES_L1,
				l2Ttl: CACHE_TTL.MARKETPLACE_ROOM_CATEGORIES_L2,
			},
		);
 
		return success(c, data);
	} catch (err) {
		return handleError(c, err);
	}
});
 
export default roomCategories;