erp-platform/ui/src/services/tenants.ts
2025-08-12 11:39:06 +03:00

37 lines
1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// scripts/tenant.ts
export type TenantDto = { name: string }
export type PagedResultDto<T> = { totalCount: number; items: T[] }
if (process.env.NODE_ENV === 'development') {
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
}
export async function fetchTenantNames(apiUrl: string): Promise<string[]> {
try {
const url = `${apiUrl.replace(/\/$/, '')}/api/app/platform-tenant?skipCount=0&maxResultCount=1000`
const response = await fetch(url, {
headers: {
Accept: 'application/json',
'X-Requested-With': 'XMLHttpRequest',
},
})
if (!response.ok) {
console.error('[vite] Tenant API hatası:', response.status, response.statusText)
return []
}
const data = (await response.json()) as PagedResultDto<TenantDto>
return (data.items ?? [])
.map((t) =>
String(t?.name || '')
.trim()
.toLowerCase(),
)
.filter(Boolean)
} catch (e) {
console.error('[vite] Tenant listesi alınamadı:', e)
return []
}
}