Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ name: PR checks

on:
pull_request:
branches:
- main
- master

jobs:
lint:
Expand Down
34 changes: 34 additions & 0 deletions app/src/adapters/RegionsAdapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { V2RegionMetadata } from '@/api/v2';
import { MetadataRegionEntry } from '@/types/metadata';

/**
* Adapter for converting between V2 API region data and internal formats
*/
export class RegionsAdapter {
/**
* Convert a single V2 region to frontend MetadataRegionEntry
*
* Maps API fields to the existing frontend region structure:
* - code -> name (the unique identifier)
* - label -> label (display name)
* - region_type -> type
* - state_code -> state_abbreviation
* - state_name -> state_name
*/
static regionFromV2(region: V2RegionMetadata): MetadataRegionEntry {
return {
name: region.code,
label: region.label,
type: region.region_type as MetadataRegionEntry['type'],
state_abbreviation: region.state_code ?? undefined,
state_name: region.state_name ?? undefined,
};
}

/**
* Convert V2 regions array to frontend MetadataRegionEntry array
*/
static regionsFromV2(regions: V2RegionMetadata[]): MetadataRegionEntry[] {
return regions.map((r) => RegionsAdapter.regionFromV2(r));
}
}
10 changes: 8 additions & 2 deletions app/src/adapters/SimulationAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,15 @@ export class SimulationAdapter {
throw new Error('Simulation must have a populationType');
}

// Map internal Simulation fields to V2-style payload
if (simulation.populationType === 'geography') {
return {
region: simulation.populationId,
policy_id: parseInt(simulation.policyId, 10),
};
}
return {
population_id: simulation.populationId,
population_type: simulation.populationType,
household_id: simulation.populationId,
policy_id: parseInt(simulation.policyId, 10),
};
}
Expand Down
42 changes: 0 additions & 42 deletions app/src/adapters/UserGeographicAdapter.ts

This file was deleted.

2 changes: 1 addition & 1 deletion app/src/adapters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ export { ReportAdapter } from './ReportAdapter';
export { HouseholdAdapter } from './HouseholdAdapter';
export { MetadataAdapter } from './MetadataAdapter';
export type { DatasetEntry } from './MetadataAdapter';
export { RegionsAdapter } from './RegionsAdapter';

// User Ingredient Adapters
export { UserReportAdapter } from './UserReportAdapter';
export { UserSimulationAdapter } from './UserSimulationAdapter';
export { UserHouseholdAdapter } from './UserHouseholdAdapter';
export { UserGeographicAdapter } from './UserGeographicAdapter';

// Conversion Helpers
export {
Expand Down
220 changes: 0 additions & 220 deletions app/src/api/geographicAssociation.ts

This file was deleted.

10 changes: 6 additions & 4 deletions app/src/api/policyAssociation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ export interface UserPolicyStore {
create: (policy: Omit<UserPolicy, 'id' | 'createdAt'>) => Promise<UserPolicy>;
findByUser: (userId: string, countryId?: string) => Promise<UserPolicy[]>;
findById: (userPolicyId: string) => Promise<UserPolicy | null>;
update: (userPolicyId: string, updates: Partial<UserPolicy>, userId: string) => Promise<UserPolicy>;
update: (
userPolicyId: string,
updates: Partial<UserPolicy>,
userId: string
) => Promise<UserPolicy>;
delete: (userPolicyId: string, userId: string) => Promise<void>;
}

Expand Down Expand Up @@ -71,9 +75,7 @@ export class LocalStoragePolicyStore implements UserPolicyStore {

async findByUser(userId: string, countryId?: string): Promise<UserPolicy[]> {
const policies = this.getStoredPolicies();
return policies.filter(
(p) => p.userId === userId && (!countryId || p.countryId === countryId)
);
return policies.filter((p) => p.userId === userId && (!countryId || p.countryId === countryId));
}

async findById(userPolicyId: string): Promise<UserPolicy | null> {
Expand Down
10 changes: 9 additions & 1 deletion app/src/api/simulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,21 @@ export async function createSimulation(
): Promise<{ result: { simulation_id: string } }> {
const url = `${BASE_URL}/${countryId}/simulation`;

// Translate V2-style payload to V1 wire format; note this is temporary
// until we migrate to v2 simulation in a future PR
const v1Payload = {
population_id: data.region ?? data.household_id,
population_type: data.region ? 'geography' : 'household',
policy_id: data.policy_id,
};

const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
},
body: JSON.stringify(data),
body: JSON.stringify(v1Payload),
});

if (!response.ok) {
Expand Down
3 changes: 3 additions & 0 deletions app/src/api/v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ export { fetchParameterValues, BASELINE_POLICY_ID } from './parameterValues';

// Datasets
export { fetchDatasets } from './datasets';

// Regions
export { fetchRegions, fetchRegionByCode, type V2RegionMetadata } from './regions';
Loading
Loading