Apps, web, i18n, UI, partners, payouts, backoffice, bariki, prod infra
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
45d7512d2b
commit
3489e0b816
319 files changed
+45483
-121
No files matched your search
@@ -0,0 +1,47 @@
|
||||
// Квартиры для страницы /ru/apartments — из CRM (crm.yandp.tech), организация AREV.
|
||||
// Ключ CRM знает только сервер лендинга: браузер ходит за фото и заявками через /api/flats/*.
|
||||
|
||||
const CRM = (process.env.CRM_URL ?? 'https://crm.yandp.tech').replace(/\/$/, '');
|
||||
const KEY = process.env.CRM_BAREV_KEY ?? '';
|
||||
|
||||
export interface Flat {
|
||||
id: number;
|
||||
/** «Описание для клиента» из карточки объекта в CRM */
|
||||
text: string;
|
||||
dealType: 'rent' | 'sale' | null;
|
||||
propertyType: string | null;
|
||||
district: string | null;
|
||||
price: number | null;
|
||||
currency: string | null;
|
||||
rooms: number | null;
|
||||
area: number | null;
|
||||
floor: number | null;
|
||||
floorsTotal: number | null;
|
||||
/** сколько фото; само фото — /api/flats/photo/<id>/<номер> */
|
||||
photos: number;
|
||||
}
|
||||
|
||||
export const crmConfigured = () => Boolean(KEY);
|
||||
|
||||
export function crmFetch(path: string, init: RequestInit & { next?: { revalidate: number } } = {}) {
|
||||
return fetch(`${CRM}${path}`, {
|
||||
...init,
|
||||
headers: { ...(init.headers ?? {}), 'x-barev-key': KEY },
|
||||
signal: init.signal ?? AbortSignal.timeout(20_000),
|
||||
});
|
||||
}
|
||||
|
||||
/** Объекты, по которым агент дозвонился и указал комиссию. null — CRM недоступна. */
|
||||
export async function getFlats(): Promise<Flat[] | null> {
|
||||
if (!KEY) return null;
|
||||
try {
|
||||
const res = await crmFetch('/api/barev/objects', {
|
||||
next: { revalidate: 60 },
|
||||
});
|
||||
if (!res.ok) throw new Error(String(res.status));
|
||||
return (await res.json()) as Flat[];
|
||||
} catch (e) {
|
||||
console.error('[flats] CRM недоступна:', e instanceof Error ? e.message : e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user