All files / utils Constants.ts

91.17% Statements 62/68
78.78% Branches 26/33
100% Functions 11/11
93.93% Lines 62/66

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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213        17x 17x   17x   17x 17x   17x   17x   17x   17x 17x 17x 17x 17x     145x     17x   17x                     17x 17x   17x   17x 17x 17x     17x   17x       90x 74x             16x               16x     16x                                 17x 17x 17x 17x 17x 17x 17x   17x           17x               17x           19x             10x           17x       34x         17x       24x   24x       8x     16x     17x       19x   19x       4x     15x           30x 12x                   90x     90x   90x       90x 14x   76x                   17x  
/**
 * Endpoints
 */
export const VUE_APP_ZMS_API_PROVIDERS_AND_SERVICES_ENDPOINT =
  "/offices-and-services/";
export const VUE_APP_ZMS_API_CALENDAR_ENDPOINT = "/available-days-by-office/";
export const VUE_APP_ZMS_API_AVAILABLE_TIME_SLOTS_ENDPOINT =
  "/available-appointments-by-office/";
export const VUE_APP_ZMS_API_RESERVE_APPOINTMENT_ENDPOINT =
  "/reserve-appointment/";
export const VUE_APP_ZMS_API_APPOINTMENT_ENDPOINT = "/appointment/";
export const VUE_APP_ZMS_API_UPDATE_APPOINTMENT_ENDPOINT =
  "/update-appointment/";
export const VUE_APP_ZMS_API_CONFIRM_APPOINTMENT_ENDPOINT =
  "/confirm-appointment/";
export const VUE_APP_ZMS_API_CANCEL_APPOINTMENT_ENDPOINT =
  "/cancel-appointment/";
export const VUE_APP_ZMS_API_PRECONFIRM_APPOINTMENT_ENDPOINT =
  "/preconfirm-appointment/";
export const VUE_APP_ZMS_API_CAPTCHA_DETAILS_ENDPOINT = "/captcha-details/";
export const VUE_APP_ZMS_API_CAPTCHA_CHALLENGE_ENDPOINT = "/captcha-challenge/";
export const VUE_APP_ZMS_API_CAPTCHA_VERIFY_ENDPOINT = "/captcha-verify/";
export const VUE_APP_ZMS_API_MYAPPOINTMENTS_ENDPOINT = "/my-appointments/";
 
export function getServiceBaseURL(): string {
  return import.meta.env.VITE_VUE_APP_SERVICE_BASE_URL;
}
 
export const MAX_SLOTS = 25;
 
export const OFTEN_SEARCHED_SERVICES = new Map<string, string>([
  ["1063475", "shortNameResidenceRegistration"],
  ["1063453", "shortNamePassport"],
  ["1063441", "shortNameIdentityCard"],
  ["10295182", "shortNameIdentityCardCollection"],
  ["10176294", "shortNameDrivingLicenseCollection"],
  ["10225119", "shortNameEidPin"],
  ["1064314", "shortNameVehicleReregistration"],
  ["1064305", "shortNameVehicleDeregistration"],
]);
 
export const QUERY_PARAM_APPOINTMENT_ID = "ap-id";
export const QUERY_PARAM_APPOINTMENT_DISPLAY_NUMBER = "ap-display";
 
export const LOCALSTORAGE_PARAM_APPOINTMENT_DATA = "lhm-appointment-data";
 
export enum APPOINTMENT_ACTION_TYPE {
  RESCHEDULE = "reschedule",
  CANCEL = "cancel",
}
 
export const API_BASE_URL_EXTENSION = "/api/citizen";
export const API_BASE_URL_AUTHENTICATED_EXTENSION =
  "/authenticated/api/citizen";
 
function getRawApiBaseURL(baseUrl: string | undefined): string {
  // Explicit override from caller always wins.
  if (baseUrl) {
    return baseUrl;
  }
 
  // Special handling for ATAF / in-container runs:
  // When the citizenview dev server is accessed via the Docker/DDEV
  // service name "citizenview" (e.g. http://citizenview:8082),
  // use a container-specific API base URL if configured.
  Iif (
    typeof window !== "undefined" &&
    window.location.hostname === "citizenview" &&
    import.meta.env.VITE_VUE_APP_API_URL_CONTAINER
  ) {
    return import.meta.env.VITE_VUE_APP_API_URL_CONTAINER;
  }
 
  Iif (import.meta.env.VITE_VUE_APP_API_URL) {
    return import.meta.env.VITE_VUE_APP_API_URL;
  } else {
    return new URL(import.meta.url).origin;
  }
}
 
/**
 * Canonical request variant IDs (see 91780800000-reorder-request-variant-ids.sql).
 *
 * | ID | DB name       |
 * |----|---------------|
 * | 1  | Präsenz       |
 * | 2  | Telefon       |
 * | 3  | Videoberatung |
 * | 4  | Einzelperson  |
 * | 5  | Familie       |
 * | 6  | Kleinkunde    |
 * | 7  | Großkunde     |
 */
export const VARIANT_ID_PRESENCE = 1;
export const VARIANT_ID_TELEPHONE = 2;
export const VARIANT_ID_VIDEO = 3;
export const VARIANT_ID_INDIVIDUAL = 4;
export const VARIANT_ID_FAMILY = 5;
export const VARIANT_ID_SMALL_CLIENT = 6;
export const VARIANT_ID_LARGE_CLIENT = 7;
 
export const VARIANTS_WITH_HINTS = [
  VARIANT_ID_PRESENCE,
  VARIANT_ID_TELEPHONE,
  VARIANT_ID_VIDEO,
] as const;
 
export const VARIANT_IDS_WITH_ADDRESS = [
  VARIANT_ID_PRESENCE,
  VARIANT_ID_LARGE_CLIENT,
  VARIANT_ID_SMALL_CLIENT,
  VARIANT_ID_FAMILY,
  VARIANT_ID_INDIVIDUAL,
] as const;
 
export const VARIANT_IDS_REQUIRING_IMPLICIT_PRESENCE = [
  VARIANT_ID_TELEPHONE,
  VARIANT_ID_VIDEO,
] as const;
 
export function isVariantWithAddress(variantId: number | null): boolean {
  return (
    variantId != null &&
    (VARIANT_IDS_WITH_ADDRESS as readonly number[]).includes(variantId)
  );
}
 
export function isVariantWithHint(variantId: number | null): boolean {
  return (
    variantId != null &&
    (VARIANTS_WITH_HINTS as readonly number[]).includes(variantId)
  );
}
 
export const getVariantHint = (
  variantId: number,
  t: (key: string) => string
): string | undefined => {
  return (VARIANTS_WITH_HINTS as readonly number[]).includes(variantId)
    ? t(`locationVariantText.${variantId}`)
    : undefined;
};
 
export const getAppointmentLocationVariantHint = (
  variantId: number | null,
  t: (key: string) => string
): string | undefined => {
  Iif (variantId == null) return undefined;
 
  if (
    variantId === VARIANT_ID_SMALL_CLIENT ||
    variantId === VARIANT_ID_LARGE_CLIENT
  ) {
    return t(`locationVariantText.${VARIANT_ID_PRESENCE}`);
  }
 
  return getVariantHint(variantId, t);
};
 
export const getAppointmentLocationVariantLabel = (
  variantId: number | null,
  t: (key: string) => string
): string | undefined => {
  Iif (variantId == null) return undefined;
 
  if (
    variantId === VARIANT_ID_SMALL_CLIENT ||
    variantId === VARIANT_ID_LARGE_CLIENT
  ) {
    return t(`appointmentTypes.${VARIANT_ID_PRESENCE}`);
  }
 
  return t(`appointmentTypes.${variantId}`);
};
 
export function shouldAddImplicitPresenceVariant(
  variantIds: Array<number | null | undefined>
): boolean {
  return variantIds.some((variantId) =>
    VARIANT_IDS_REQUIRING_IMPLICIT_PRESENCE.includes(
      variantId as (typeof VARIANT_IDS_REQUIRING_IMPLICIT_PRESENCE)[number]
    )
  );
}
 
export function getAPIBaseURL(
  baseUrl: string | undefined,
  authenticated: boolean
): string {
  let url = getRawApiBaseURL(baseUrl);
 
  // Can be deleted if the configurations have been adjusted on all environments.
  Iif (url.endsWith("/api/citizen")) {
    url = url.slice(0, -"/api/citizen".length);
  } else Iif (url.endsWith("/api/citizen/")) {
    url = url.slice(0, -"/api/citizen/".length);
  }
 
  if (authenticated) {
    return url + API_BASE_URL_AUTHENTICATED_EXTENSION;
  } else {
    return url + API_BASE_URL_EXTENSION;
  }
}
 
/**
 * UI thresholds and limits
 */
// ZMSKVR-110: UX rule for view mode
// Few appointments → group by am/pm (≤ 18 per day); many appointments → hourly (> 18)
// Rationale: accessibility and layout density tradeoff documented in the ticket.
export const APPOINTMENTS_THRESHOLD_FOR_HOURLY_VIEW = 18;