init to pos domain

This commit is contained in:
2026-03-18 13:35:57 +03:30
parent f2766e2d7d
commit 1e2f94261e
42 changed files with 635 additions and 809 deletions
@@ -1,11 +1,15 @@
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { inject, Injectable } from '@angular/core';
import { CookieService } from 'ngx-cookie-service';
import { Observable } from 'rxjs';
import { environment } from 'src/environments/environment';
@Injectable()
export class ApiBaseUrlInterceptor implements HttpInterceptor {
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
console.log('first');
const cookieService = inject(CookieService);
// Prepare default headers but don't overwrite existing ones
const defaultHeaders: Record<string, string> = {
Accept: 'application/json',
@@ -14,6 +18,13 @@ export class ApiBaseUrlInterceptor implements HttpInterceptor {
};
const headersToSet: Record<string, string> = {};
if (req.url === '/api/v1/pos' || req.url.startsWith('/api/v1/pos/')) {
headersToSet['pos_Id'] = cookieService.get('posId');
// req.headers.set('posId', cookieService.get('posId'));
}
const isFormData = req.body instanceof FormData;
Object.keys(defaultHeaders).forEach((k) => {
if (k === 'Content-Type' && isFormData) return;
@@ -22,6 +33,9 @@ export class ApiBaseUrlInterceptor implements HttpInterceptor {
}
});
console.log('req.url');
console.log(req.url);
// Only prepend base URL if the request URL is relative (does not start with http or https)
if (!/^https?:\/\//i.test(req.url)) {
const apiReq = req.clone({ url: environment.apiBaseUrl + req.url, setHeaders: headersToSet });