Sprint 9: add tenant-driven API resolution layer

This commit is contained in:
sdarbinyan
2026-07-05 02:24:16 +04:00
parent c3d1153f0e
commit 487a3fb913
12 changed files with 197 additions and 17 deletions

View File

@@ -0,0 +1,14 @@
import { Injectable, inject } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { ApiConfigService } from '../core/config/api-config.service';
@Injectable({ providedIn: 'root' })
export class ApiHealthService {
private readonly http = inject(HttpClient);
private readonly apiConfig = inject(ApiConfigService);
ping(): Observable<{ message: string }> {
return this.http.get<{ message: string }>(`${this.apiConfig.getBaseUrl()}/ping`);
}
}

View File

@@ -5,6 +5,7 @@ import { map, retry } from 'rxjs/operators';
import { Category, DeliveryOption, Item, Subcategory } from '../models';
import { normalizeDeliveryOption, normalizeOptionalNumber } from '../utils/normalization.utils';
import { environment } from '../../environments/environment';
import { ApiConfigService } from '../core/config/api-config.service';
export interface QrCreateRequest {
qrtype: 'QRDynamic';
@@ -68,7 +69,6 @@ export interface QrDynamicStatusResponse {
providedIn: 'root'
})
export class ApiService {
private readonly baseUrl = environment.apiUrl;
private readonly qrBaseUrl = (environment as any).qrApiUrl as string;
private readonly cartPaymentPartnerId = 'web-97ec-9c57-4dde-9037-3a68f7f83750';
@@ -77,7 +77,14 @@ export class ApiService {
delay: (_error: unknown, retryCount: number) => timer(Math.pow(2, retryCount) * 500)
};
constructor(private http: HttpClient) {}
constructor(
private readonly http: HttpClient,
private readonly apiConfig: ApiConfigService
) {}
private get baseUrl(): string {
return this.apiConfig.getBaseUrl();
}
/** Map API language codes (RU/EN/AM) → frontend codes (ru/en/hy) */
private normalizeLang(apiLang: string): string {

View File

@@ -1,7 +1,7 @@
import { Injectable, signal, computed } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Region, GeoIpResponse } from '../models/location.model';
import { environment } from '../../environments/environment';
import { ApiConfigService } from '../core/config/api-config.service';
const STORAGE_KEY = 'selected_region';
@@ -26,16 +26,17 @@ export class LocationService {
/** Computed region id for API calls — empty string means global */
readonly regionId = computed(() => this.regionSignal()?.id ?? '');
private readonly apiUrl = environment.apiUrl;
constructor(private http: HttpClient) {
constructor(
private readonly http: HttpClient,
private readonly apiConfig: ApiConfigService
) {
this.loadRegions();
this.restoreFromStorage();
}
/** Fetch available regions from backend */
loadRegions(): void {
this.http.get<Region[]>(`${this.apiUrl}/regions`).subscribe({
this.http.get<Region[]>(`${this.apiConfig.getBaseUrl()}/regions`).subscribe({
next: (regions) => {
this.regionsSignal.set(regions);
// If we have a stored region, validate it still exists