fix: restore Velocity-OS pillar data contracts
Some checks failed
Velocity-OS Deployment Pipeline / lint (push) Has been cancelled
Velocity-OS Deployment Pipeline / build-and-push (agents) (push) Has been cancelled
Velocity-OS Deployment Pipeline / build-and-push (core) (push) Has been cancelled
Velocity-OS Deployment Pipeline / build-and-push (media-engine) (push) Has been cancelled
Velocity-OS Deployment Pipeline / build-and-push (webos) (push) Has been cancelled
Velocity-OS Deployment Pipeline / sign-images (agents) (push) Has been cancelled
Velocity-OS Deployment Pipeline / sign-images (core) (push) Has been cancelled
Velocity-OS Deployment Pipeline / sign-images (media-engine) (push) Has been cancelled
Velocity-OS Deployment Pipeline / sign-images (webos) (push) Has been cancelled
Velocity-OS Deployment Pipeline / notify-ingress (push) Has been cancelled

This commit is contained in:
2026-05-01 18:43:38 +05:30
parent 55d0c3a8c4
commit 103900c58a
3 changed files with 190 additions and 6 deletions

View File

@@ -7,7 +7,15 @@ import { api } from '@/shared/lib/apiClient';
export function useStudioProperties() {
const query = useQuery({
queryKey: ['studio-properties'],
queryFn: () => api.get<StudioProperty[]>('/inventory/properties'),
queryFn: async () => {
const response = await api.get<InventoryPropertiesResponse | StudioProperty[]>('/inventory/properties');
const rawProperties = Array.isArray(response)
? response
: Array.isArray(response.properties)
? response.properties
: [];
return rawProperties.map(mapInventoryProperty);
},
staleTime: 120_000,
});
return { properties: query.data ?? [], isLoading: query.isLoading };
@@ -19,7 +27,9 @@ export function useStudioProperties() {
export function useProperty(propertyId: string) {
const query = useQuery({
queryKey: ['property', propertyId],
queryFn: () => api.get<PropertyDetail>(`/inventory/properties/${propertyId}`),
queryFn: async () => mapInventoryPropertyDetail(
await api.get<InventoryPropertyRecord>(`/inventory/properties/${propertyId}`)
),
staleTime: 120_000,
enabled: !!propertyId,
});
@@ -49,3 +59,82 @@ export interface PropertyDetail {
images?: string[];
amenities?: string[];
}
interface InventoryPropertiesResponse {
properties?: InventoryPropertyRecord[];
}
interface InventoryPropertyRecord {
property_id?: string;
id?: string;
project_name?: string;
name?: string;
developer_name?: string;
property_type?: string;
location?: {
city?: string;
district?: string;
area?: string;
address?: string;
};
price_bands?: Array<{ label?: string; min?: number; max?: number; currency?: string }>;
unit_mix?: Array<{ configuration?: string; count?: number; available?: number; area?: string; price?: string }>;
amenities?: string[];
media?: Array<{ url?: string; thumbnail_url?: string }>;
images?: string[];
thumbnailUrl?: string;
availableUnits?: number;
}
function mapLocation(location: InventoryPropertyRecord['location']): string {
if (!location) return 'Location pending';
return [location.district, location.area, location.city, location.address].filter(Boolean).join(', ') || 'Location pending';
}
function mapPriceRange(priceBands: InventoryPropertyRecord['price_bands']): string | undefined {
if (!Array.isArray(priceBands) || priceBands.length === 0) return undefined;
const mins = priceBands.map((band) => Number(band.min)).filter(Number.isFinite);
const maxes = priceBands.map((band) => Number(band.max)).filter(Number.isFinite);
if (!mins.length && !maxes.length) return priceBands[0]?.label;
const currency = priceBands[0]?.currency ?? 'INR';
const min = mins.length ? Math.min(...mins) : undefined;
const max = maxes.length ? Math.max(...maxes) : undefined;
if (min !== undefined && max !== undefined) return `${currency} ${min} - ${max}`;
if (min !== undefined) return `From ${currency} ${min}`;
return `Up to ${currency} ${max}`;
}
function mapInventoryProperty(record: InventoryPropertyRecord): StudioProperty {
const mediaThumb = Array.isArray(record.media) ? record.media.find((item) => item.thumbnail_url || item.url) : undefined;
const availableUnits = Array.isArray(record.unit_mix)
? record.unit_mix.reduce((sum, unit) => sum + Number(unit.available ?? unit.count ?? 0), 0)
: record.availableUnits;
const stableId = record.property_id ?? record.id ?? record.project_name ?? record.name ?? 'unknown-property';
return {
id: String(stableId),
name: record.project_name ?? record.name ?? 'Unnamed property',
location: mapLocation(record.location),
priceRange: mapPriceRange(record.price_bands),
thumbnailUrl: record.thumbnailUrl ?? mediaThumb?.thumbnail_url ?? mediaThumb?.url,
availableUnits,
};
}
function mapInventoryPropertyDetail(record: InventoryPropertyRecord): PropertyDetail {
const base = mapInventoryProperty(record);
const primaryUnit = Array.isArray(record.unit_mix) ? record.unit_mix[0] : undefined;
const images = Array.isArray(record.images)
? record.images
: Array.isArray(record.media)
? record.media.map((item) => item.url).filter((url): url is string => Boolean(url))
: [];
return {
...base,
config: primaryUnit?.configuration ?? record.property_type ?? 'Mixed configuration',
area: primaryUnit?.area ?? 'Area pending',
price: primaryUnit?.price ?? base.priceRange ?? 'Price pending',
description: `${record.developer_name ?? 'Developer'} property in ${base.location}`,
images,
amenities: Array.isArray(record.amenities) ? record.amenities : [],
};
}