integration new apis

This commit is contained in:
sdarbinyan
2026-03-24 00:09:11 +04:00
parent 3445f55758
commit 56f4c56b9e
47 changed files with 2603 additions and 1577 deletions

View File

@@ -18,7 +18,8 @@ export class ApiService {
* legacy marketplace format and the new backOffice API format.
*/
private normalizeItem(raw: any): Item {
const item: Item = { ...raw };
const { partnerID, ...rest } = raw;
const item: Item = { ...rest };
// Map backOffice string id → legacy numeric itemID
if (raw.id != null && raw.itemID == null) {
@@ -30,6 +31,13 @@ export class ApiService {
if (raw.imgs && (!raw.photos || raw.photos.length === 0)) {
item.photos = raw.imgs.map((url: string) => ({ url }));
}
// Normalize photo type: API sends type='video'|'photo', template checks .video
if (item.photos) {
item.photos = item.photos.map((p: any) => ({
...p,
video: p.video || (p.type === 'video' ? p.url : undefined),
}));
}
item.imgs = raw.imgs || raw.photos?.map((p: any) => p.url) || [];
// Map backOffice description (key-value array) → legacy description string
@@ -40,6 +48,33 @@ export class ApiService {
item.description = raw.description || raw.simpleDescription || '';
}
// Map backend names[] → translations (multi-lang name support)
if (raw.names && Array.isArray(raw.names)) {
item.names = raw.names;
if (!item.translations) item.translations = {};
for (const entry of raw.names) {
if (!item.translations[entry.language]) item.translations[entry.language] = {};
item.translations[entry.language].name = entry.value;
}
}
// Map backend descriptions[] → translations (multi-lang descriptions)
if (raw.descriptions && Array.isArray(raw.descriptions)) {
item.descriptions = raw.descriptions;
if (!item.translations) item.translations = {};
for (const entry of raw.descriptions) {
if (!item.translations[entry.language]) item.translations[entry.language] = {};
item.translations[entry.language].simpleDescription = entry.value;
}
}
// Preserve attributes from backend
item.attributes = raw.attributes || [];
// Preserve colour & size
item.colour = raw.colour || '';
item.size = raw.size || '';
// Map backOffice comments → legacy callbacks
if (raw.comments && (!raw.callbacks || raw.callbacks.length === 0)) {
item.callbacks = raw.comments.map((c: any) => ({
@@ -77,7 +112,7 @@ export class ApiService {
item.badges = raw.badges || [];
item.tags = raw.tags || [];
item.simpleDescription = raw.simpleDescription || '';
item.translations = raw.translations || {};
item.translations = item.translations || raw.translations || {};
item.visible = raw.visible ?? true;
item.priority = raw.priority ?? 0;

View File

@@ -9,11 +9,18 @@ export interface Language {
enabled: boolean;
}
export interface Currency {
code: string;
symbol: string;
name: string;
}
@Injectable({
providedIn: 'root'
})
export class LanguageService {
private currentLanguageSignal = signal<string>('ru');
private currentCurrencySignal = signal<string>('RUB');
languages: Language[] = [
{ code: 'ru', name: 'Русский', flag: '🇷🇺', flagSvg: '/flags/ru.svg', enabled: true },
@@ -21,7 +28,15 @@ export class LanguageService {
{ code: 'hy', name: 'Հայերեն', flag: '🇦🇲', flagSvg: '/flags/arm.svg', enabled: true }
];
currencies: Currency[] = [
{ code: 'RUB', symbol: '₽', name: 'Рубль' },
{ code: 'USD', symbol: '$', name: 'Dollar' },
{ code: 'EUR', symbol: '€', name: 'Euro' },
{ code: 'AMD', symbol: '֏', name: 'Դրամ' },
];
currentLanguage = this.currentLanguageSignal.asReadonly();
currentCurrency = this.currentCurrencySignal.asReadonly();
constructor(private router: Router) {
// Load saved language from localStorage
@@ -29,6 +44,11 @@ export class LanguageService {
if (savedLang && this.languages.find(l => l.code === savedLang && l.enabled)) {
this.currentLanguageSignal.set(savedLang);
}
const savedCurrency = localStorage.getItem('selectedCurrency');
if (savedCurrency && this.currencies.find(c => c.code === savedCurrency)) {
this.currentCurrencySignal.set(savedCurrency);
}
}
setLanguage(langCode: string): void {
@@ -39,6 +59,18 @@ export class LanguageService {
}
}
setCurrency(code: string): void {
const currency = this.currencies.find(c => c.code === code);
if (currency) {
this.currentCurrencySignal.set(code);
localStorage.setItem('selectedCurrency', code);
}
}
getCurrentCurrency(): Currency | undefined {
return this.currencies.find(c => c.code === this.currentCurrencySignal());
}
/** Change language and navigate to the same page with the new prefix */
switchLanguage(langCode: string): void {
const lang = this.languages.find(l => l.code === langCode);