fix: complete InvesteMoz validation and error corrections
This commit is contained in:
@@ -4,31 +4,66 @@ const searchRoutes = ['/carteira', '/oportunidades', '/zonas', '/educacao'];
|
||||
/** Keep search geography explicit; a documentary origin is never an invented offer. */
|
||||
export function portfolioPreparationHref(id: string, pageUrl: string): string {
|
||||
const source = new URL(pageUrl, 'https://portal.invalid');
|
||||
const inherited = source.searchParams.has('catalogue_query') ? new URLSearchParams(source.searchParams.get('catalogue_query')!) : source.searchParams;
|
||||
const query = new URLSearchParams({source: `portfolio:${id}`});
|
||||
for (const field of levels) if (inherited.get(field)) query.set(field, inherited.get(field)!);
|
||||
const inherited = source.searchParams.has('catalogue_query')
|
||||
? new URLSearchParams(source.searchParams.get('catalogue_query')!)
|
||||
: source.searchParams;
|
||||
const query = new URLSearchParams({ source: `portfolio:${id}` });
|
||||
for (const field of levels)
|
||||
if (inherited.get(field)) query.set(field, inherited.get(field)!);
|
||||
return '/investimentos/iniciar?' + query.toString();
|
||||
}
|
||||
|
||||
/** Preserve an explicit complementary selection while consulting its canonical public fiche. */
|
||||
export function complementPreparationHref(pageUrl: string, target?: string): string | null {
|
||||
export function complementPreparationHref(
|
||||
pageUrl: string,
|
||||
target?: string,
|
||||
): string | null {
|
||||
const params = new URL(pageUrl, 'https://portal.invalid').searchParams;
|
||||
if (!params.get('complement_origin') || !params.get('complement_code') || (target && params.get('complement_target') !== target)) return null;
|
||||
if (
|
||||
!params.get('complement_origin') ||
|
||||
!params.get('complement_code') ||
|
||||
(target && params.get('complement_target') !== target)
|
||||
)
|
||||
return null;
|
||||
const query = new URLSearchParams();
|
||||
for (const field of ['complement_origin', 'complement_code', 'complement_target', 'complement_territory', 'selection_key']) if(params.get(field)) query.set(field,params.get(field)!);
|
||||
for (const field of [
|
||||
'complement_origin',
|
||||
'complement_code',
|
||||
'complement_target',
|
||||
'complement_territory',
|
||||
'selection_key',
|
||||
])
|
||||
if (params.get(field)) query.set(field, params.get(field)!);
|
||||
const dossier = params.get('investment_dossier');
|
||||
return (dossier && /^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test(dossier) ? `/investimentos/${dossier}/contexto/editar` : '/investimentos/iniciar')+'?'+query;
|
||||
return (
|
||||
(dossier &&
|
||||
/^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test(dossier)
|
||||
? `/investimentos/${dossier}/contexto/editar`
|
||||
: '/investimentos/iniciar') +
|
||||
'?' +
|
||||
query
|
||||
);
|
||||
}
|
||||
|
||||
/** Carry the explicitly consulted portfolio origin and search geography into the existing preparation entry. */
|
||||
export function investmentPreparationHref(opportunity: number, pageUrl: string, origin?: string | null): string {
|
||||
const complementary = complementPreparationHref(pageUrl, `opportunity:${opportunity}`);
|
||||
export function investmentPreparationHref(
|
||||
opportunity: number,
|
||||
pageUrl: string,
|
||||
origin?: string | null,
|
||||
): string {
|
||||
const complementary = complementPreparationHref(
|
||||
pageUrl,
|
||||
`opportunity:${opportunity}`,
|
||||
);
|
||||
if (complementary) return complementary;
|
||||
const source = new URL(pageUrl, 'https://portal.invalid');
|
||||
const inherited = source.searchParams.has('catalogue_query') ? new URLSearchParams(source.searchParams.get('catalogue_query')!) : source.searchParams;
|
||||
const query = new URLSearchParams({source: `opportunity:${opportunity}`});
|
||||
const inherited = source.searchParams.has('catalogue_query')
|
||||
? new URLSearchParams(source.searchParams.get('catalogue_query')!)
|
||||
: source.searchParams;
|
||||
const query = new URLSearchParams({ source: `opportunity:${opportunity}` });
|
||||
if (origin) query.set('from_dossier', origin);
|
||||
for (const field of levels) if (inherited.get(field)) query.set(field, inherited.get(field)!);
|
||||
for (const field of levels)
|
||||
if (inherited.get(field)) query.set(field, inherited.get(field)!);
|
||||
return '/investimentos/iniciar?' + query.toString();
|
||||
}
|
||||
|
||||
@@ -37,8 +72,16 @@ export function searchTerritoryHref(href: string, pageUrl: string): string {
|
||||
const base = 'https://portal.invalid';
|
||||
const source = new URL(pageUrl, base);
|
||||
const target = new URL(href, base);
|
||||
const supported = (path: string) => searchRoutes.some((route) => path === route || path.startsWith(`${route}/`));
|
||||
if (target.origin !== base || !supported(source.pathname) || !supported(target.pathname)) return href;
|
||||
const supported = (path: string) =>
|
||||
searchRoutes.some(
|
||||
(route) => path === route || path.startsWith(`${route}/`),
|
||||
);
|
||||
if (
|
||||
target.origin !== base ||
|
||||
!supported(source.pathname) ||
|
||||
!supported(target.pathname)
|
||||
)
|
||||
return href;
|
||||
const inherited = source.searchParams.has('catalogue_query')
|
||||
? new URLSearchParams(source.searchParams.get('catalogue_query')!)
|
||||
: source.searchParams;
|
||||
|
||||
Reference in New Issue
Block a user