All files / src/lib/api/admin room-categories.ts

100% Statements 7/7
100% Branches 5/5
100% Functions 5/5
100% Lines 7/7

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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76                                                          95x   1x           1x                 2x       2x           1x                   1x                  
import { request } from "../base";
 
export type RoomCategoryMedia = {
	id: number;
	url: string;
	altText: string | null;
	proName: string;
	proBusinessName: string;
	projectTitle: string;
	projectId: string;
	uploadedAt: string;
	viewCount: number;
};
 
export type RoomCategoryWithStats = {
	code: string;
	label: string;
	sortOrder: number;
	coverMediaId: number | null;
	coverMediaUrl: string | null;
	coverMediaAlt: string | null;
	coverProjectTitle: string | null;
	coverProName: string | null;
	coverUploadedAt: string | null;
	coverSource: "curated" | "algorithmic" | "empty";
	projectCount: number;
	photoCount: number;
};
 
export const adminRoomCategoriesApi = {
	async listRoomCategoriesWithStats() {
		return request<RoomCategoryWithStats[]>(
			`/api/admin/taxonomy/roomTypes/list-with-stats`,
		);
	},
 
	async getRoomCategory(code: string) {
		return request<RoomCategoryWithStats>(
			`/api/admin/taxonomy/roomTypes/${code}/with-stats`,
		);
	},
 
	async listMediaForRoomType(
		code: string,
		opts: { limit?: number; sortBy?: "recent" | "popular" } = {},
	) {
		const params = new URLSearchParams({
			limit: String(opts.limit ?? 100),
			sortBy: opts.sortBy ?? "recent",
		});
		return request<RoomCategoryMedia[]>(
			`/api/admin/taxonomy/roomTypes/${code}/media?${params}`,
		);
	},
 
	async setRoomCategoryCover(code: string, mediaId: number) {
		return request<RoomCategoryWithStats>(
			`/api/admin/taxonomy/roomTypes/${code}/cover`,
			{
				method: "PUT",
				body: { coverMediaId: mediaId },
			},
		);
	},
 
	async clearRoomCategoryCover(code: string) {
		return request<RoomCategoryWithStats>(
			`/api/admin/taxonomy/roomTypes/${code}/cover`,
			{
				method: "PUT",
				body: { coverMediaId: null },
			},
		);
	},
};