Files
Investidor-V2/resources/js/lib/preparation-intent.ts
T
2026-11-15 18:56:39 +02:00

51 lines
1.8 KiB
TypeScript

/** Only confirmed context becomes a criterion; titles never assign a sector. */
export function preparationSearch(
query: string,
sector: string,
path: { id: string; location_type: string }[],
) {
const params = new URLSearchParams();
if (query.trim()) params.set('q', query.trim());
if (/^sector:[1-9]\d*$/.test(sector))
params.set('sector_id', sector.slice(7));
for (const place of path)
if (
['province', 'district', 'admin_post', 'locality'].includes(
place.location_type,
)
)
params.set(place.location_type + '_id', place.id);
return params.toString();
}
/** Carry only deliberate preparation criteria, never catalogue relationships. */
export function createInvestmentHref(
values: Record<string, unknown>,
path: { id: string; location_type: string }[] = [],
) {
const query = new URLSearchParams();
for (const key of ['sector_id', 'project_title', 'currency']) {
if (typeof values[key] === 'string' && values[key])
query.set(key, values[key]);
}
if (typeof values.sector === 'string' && values.sector)
query.set('sector', values.sector);
for (const [from, to] of [
['min_amount', 'investment_budget_min'],
['max_amount', 'investment_budget_max'],
] as const) {
if (typeof values[from] === 'string' && values[from] !== '')
query.set(to, values[from]);
}
for (const place of path)
if (
['province', 'district', 'admin_post', 'locality'].includes(
place.location_type,
)
)
query.set(place.location_type + '_id', place.id);
return (
'/investimentos/iniciar' + (query.size ? '?' + query.toString() : '')
);
}