feat: consolidar desenvolvimentos do portal InvestMoz
This commit is contained in:
@@ -5,6 +5,58 @@ export type BusinessLocationPath = {
|
||||
locality_id: string;
|
||||
};
|
||||
|
||||
export function businessPointTerritoryKey(path: BusinessLocationPath): string {
|
||||
return [
|
||||
path.province_id,
|
||||
path.district_id,
|
||||
path.admin_post_id,
|
||||
path.locality_id,
|
||||
].join('|');
|
||||
}
|
||||
|
||||
export function businessPointTerritoryLabel(
|
||||
payload: Record<string, string | undefined>,
|
||||
paths: string[][] = [],
|
||||
): string {
|
||||
const index =
|
||||
payload.geography_scope === 'specific'
|
||||
? 0
|
||||
: decodeBusinessLocations(payload.locations_json).findIndex(
|
||||
(path) =>
|
||||
businessPointTerritoryKey(path) ===
|
||||
payload.location_point_territory,
|
||||
);
|
||||
return paths[index]?.join(' / ') || 'Localização por reconciliar';
|
||||
}
|
||||
|
||||
export function businessPointApplicable(
|
||||
payload: Record<string, string | undefined>,
|
||||
): boolean {
|
||||
return (
|
||||
payload.location_point_enabled === 'yes' &&
|
||||
['specific', 'multiple'].includes(payload.geography_scope ?? '') &&
|
||||
payload.disclosure_precision === 'exact' &&
|
||||
payload.location_unknown === 'no'
|
||||
);
|
||||
}
|
||||
|
||||
export function businessPointRequiredFields(
|
||||
payload: Record<string, string | undefined>,
|
||||
): Set<string> {
|
||||
if (!businessPointApplicable(payload)) return new Set();
|
||||
return new Set([
|
||||
'location_latitude',
|
||||
'location_longitude',
|
||||
'location_point_source_mode',
|
||||
...(payload.geography_scope === 'multiple'
|
||||
? ['location_point_territory']
|
||||
: []),
|
||||
...(payload.location_point_source_mode === 'custom'
|
||||
? ['location_point_source_reference']
|
||||
: []),
|
||||
]);
|
||||
}
|
||||
|
||||
export const emptyBusinessLocation = (): BusinessLocationPath => ({
|
||||
province_id: '',
|
||||
district_id: '',
|
||||
|
||||
Reference in New Issue
Block a user