All files / src/lib track-list-query.ts

100% Statements 42/42
100% Branches 9/9
100% Functions 1/1
100% Lines 42/42

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        1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x     1x 7x 7x 140x 140x 10x 64x 9x 9x 140x 7x 7x 7x  
/**
 * Зеркало querystring GET /tracks в gpx-catalog-service (track-list-filters.ts).
 * При изменении контракта каталога — обновить и здесь.
 */
export const trackListQuerystringSchema = {
  type: "object",
  additionalProperties: false,
  properties: {
    trackTypeCode: { type: "string" },
    name: { type: "string" },
    locality: { type: "string" },
    routeLayoutCode: { type: "string" },
    distanceKmMin: { type: "string" },
    distanceKmMax: { type: "string" },
    elevationMMin: { type: "string" },
    elevationMMax: { type: "string" },
    surfaceQualityMin: { type: "string" },
    surfaceQualityMax: { type: "string" },
    difficultyMin: { type: "string" },
    difficultyMax: { type: "string" },
    sceneryMin: { type: "string" },
    sceneryMax: { type: "string" },
    safetyMin: { type: "string" },
    safetyMax: { type: "string" },
    sort: { type: "string" },
    order: { type: "string" },
    page: { type: "string" },
    pageSize: { type: "string" },
  },
} as const;
 
const TRACK_LIST_QUERY_KEYS = Object.keys(
  trackListQuerystringSchema.properties,
) as (keyof typeof trackListQuerystringSchema.properties)[];
 
/** Собрать query для upstream GET /tracks (только известные ключи, непустые значения). */
export function buildTrackListSearchParams(query: Record<string, unknown>): string {
  const params = new URLSearchParams();
  for (const key of TRACK_LIST_QUERY_KEYS) {
    const raw = query[key];
    if (raw === undefined || raw === null) continue;
    const value = String(raw).trim();
    if (value.length > 0) {
      params.set(key, value);
    }
  }
  const serialized = params.toString();
  return serialized.length > 0 ? `?${serialized}` : "";
}