Skip to content
72 changes: 46 additions & 26 deletions app/src/api/geographicAssociation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ export interface UserGeographicStore {
create: (population: UserGeographyPopulation) => Promise<UserGeographyPopulation>;
findByUser: (userId: string, countryId?: string) => Promise<UserGeographyPopulation[]>;
findById: (userId: string, geographyId: string) => Promise<UserGeographyPopulation | null>;
update: (
userId: string,
geographyId: string,
updates: Partial<UserGeographyPopulation>
) => Promise<UserGeographyPopulation>;
// The below are not yet implemented, but keeping for future use
// update(userId: string, geographyId: string, updates: Partial<UserGeographyPopulation>): Promise<UserGeographyPopulation>;
// delete(userId: string, geographyId: string): Promise<void>;
}

Expand Down Expand Up @@ -67,22 +71,25 @@ export class ApiGeographicStore implements UserGeographicStore {
return UserGeographicAdapter.fromApiResponse(apiData);
}

// Not yet implemented, but keeping for future use
/*
async update(userId: string, geographyId: string, updates: Partial<UserGeographyPopulation>): Promise<UserGeographyPopulation> {
const response = await fetch(`/api/user-geographic-associations/${userId}/${geographyId}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(updates),
});

if (!response.ok) {
throw new Error('Failed to update association');
}
async update(
_userId: string,
_geographyId: string,
_updates: Partial<UserGeographyPopulation>
): Promise<UserGeographyPopulation> {
// TODO: Implement when backend API endpoint is available
// Expected endpoint: PUT /api/user-geographic-associations/:userId/:geographyId
// Expected payload: UserGeographicUpdatePayload (to be created)

console.warn(
'[ApiGeographicStore.update] API endpoint not yet implemented. ' +
'This method will be activated when user authentication is added.'
);

return response.json();
throw new Error(
'Geographic population updates via API are not yet supported. ' +
'Please ensure you are using localStorage mode.'
);
}
*/

// Not yet implemented, but keeping for future use
/*
Expand Down Expand Up @@ -136,23 +143,36 @@ export class LocalStorageGeographicStore implements UserGeographicStore {
return populations.find((p) => p.userId === userId && p.geographyId === geographyId) || null;
}

// Not yet implemented, but keeping for future use
/*
async update(userId: string, geographyId: string, updates: Partial<UserGeographyPopulation>): Promise<UserGeographyPopulation> {
async update(
userId: string,
geographyId: string,
updates: Partial<UserGeographyPopulation>
): Promise<UserGeographyPopulation> {
const populations = this.getStoredPopulations();
const index = populations.findIndex(p => p.userId === userId && p.geographyId === geographyId);


// Find by userId and geographyId composite key
const index = populations.findIndex(
(g) => g.userId === userId && g.geographyId === geographyId
);

if (index === -1) {
throw new Error('Geographic population not found');
throw new Error(
`UserGeography with userId ${userId} and geographyId ${geographyId} not found`
);
}

const updatedPopulation = { ...populations[index], ...updates };
populations[index] = updatedPopulation;

// Merge updates and set timestamp
const updated: UserGeographyPopulation = {
...populations[index],
...updates,
updatedAt: new Date().toISOString(),
};

populations[index] = updated;
this.setStoredPopulations(populations);
return updatedPopulation;

return updated;
}
*/

// Not yet implemented, but keeping for future use
/*
Expand Down
65 changes: 39 additions & 26 deletions app/src/api/householdAssociation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ export interface UserHouseholdStore {
create: (association: UserHouseholdPopulation) => Promise<UserHouseholdPopulation>;
findByUser: (userId: string, countryId?: string) => Promise<UserHouseholdPopulation[]>;
findById: (userId: string, householdId: string) => Promise<UserHouseholdPopulation | null>;
update: (
userHouseholdId: string,
updates: Partial<UserHouseholdPopulation>
) => Promise<UserHouseholdPopulation>;
// The below are not yet implemented, but keeping for future use
// update(userId: string, householdId: string, updates: Partial<UserHouseholdPopulation>): Promise<UserHouseholdPopulation>;
// delete(userId: string, householdId: string): Promise<void>;
}

Expand Down Expand Up @@ -64,22 +67,24 @@ export class ApiHouseholdStore implements UserHouseholdStore {
return UserHouseholdAdapter.fromApiResponse(apiData);
}

// Not yet implemented, but keeping for future use
/*
async update(userId: string, householdId: string, updates: Partial<UserHousehold>): Promise<UserHousehold> {
const response = await fetch(`/api/user-population-households/${userId}/${householdId}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(updates),
});

if (!response.ok) {
throw new Error('Failed to update association');
}
async update(
_userHouseholdId: string,
_updates: Partial<UserHouseholdPopulation>
): Promise<UserHouseholdPopulation> {
// TODO: Implement when backend API endpoint is available
// Expected endpoint: PUT /api/user-household-associations/:userHouseholdId
// Expected payload: UserHouseholdUpdatePayload (to be created)

console.warn(
'[ApiHouseholdStore.update] API endpoint not yet implemented. ' +
'This method will be activated when user authentication is added.'
);

return response.json();
throw new Error(
'Household updates via API are not yet supported. ' +
'Please ensure you are using localStorage mode.'
);
}
*/

// Not yet implemented, but keeping for future use
/*
Expand Down Expand Up @@ -134,23 +139,31 @@ export class LocalStorageHouseholdStore implements UserHouseholdStore {
return households.find((h) => h.userId === userId && h.householdId === householdId) || null;
}

// Not yet implemented, but keeping for future use
/*
async update(userId: string, householdId: string, updates: Partial<UserHousehold>): Promise<UserHousehold> {
async update(
userHouseholdId: string,
updates: Partial<UserHouseholdPopulation>
): Promise<UserHouseholdPopulation> {
const households = this.getStoredHouseholds();
const index = households.findIndex(a => a.userId === userId && a.householdId === householdId);


// Find by userHousehold.id (the "suh-" prefixed ID), NOT householdId
const index = households.findIndex((h) => h.id === userHouseholdId);

if (index === -1) {
throw new Error('Association not found');
throw new Error(`UserHousehold with id ${userHouseholdId} not found`);
}

const updatedAssociation = { ...households[index], ...updates };
households[index] = updatedAssociation;

// Merge updates and set timestamp
const updated: UserHouseholdPopulation = {
...households[index],
...updates,
updatedAt: new Date().toISOString(),
};

households[index] = updated;
this.setStoredHouseholds(households);
return updatedAssociation;

return updated;
}
*/

// Not yet implemented, but keeping for future use
/*
Expand Down
50 changes: 26 additions & 24 deletions app/src/api/policyAssociation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ export interface UserPolicyStore {
create: (policy: Omit<UserPolicy, 'id' | 'createdAt'>) => Promise<UserPolicy>;
findByUser: (userId: string, countryId?: string) => Promise<UserPolicy[]>;
findById: (userId: string, policyId: string) => Promise<UserPolicy | null>;
update: (userPolicyId: string, updates: Partial<UserPolicy>) => Promise<UserPolicy>;
// The below are not yet implemented, but keeping for future use
// update(userId: string, policyId: string, updates: Partial<UserPolicy>): Promise<UserPolicy>;
// delete(userId: string, policyId: string): Promise<void>;
// delete(userPolicyId: string): Promise<void>;
}

export class ApiPolicyStore implements UserPolicyStore {
Expand Down Expand Up @@ -64,22 +64,21 @@ export class ApiPolicyStore implements UserPolicyStore {
return UserPolicyAdapter.fromApiResponse(apiData);
}

// Not yet implemented, but keeping for future use
/*
async update(userId: string, policyId: string, updates: Partial<UserPolicy>): Promise<UserPolicy> {
const response = await fetch(`/api/user-policy-associations/${userId}/${policyId}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(updates),
});
async update(_userPolicyId: string, _updates: Partial<UserPolicy>): Promise<UserPolicy> {
// TODO: Implement when backend API endpoint is available
// Expected endpoint: PUT /api/user-policy-associations/:userPolicyId
// Expected payload: UserPolicyUpdatePayload (to be created)

if (!response.ok) {
throw new Error('Failed to update association');
}
console.warn(
'[ApiPolicyStore.update] API endpoint not yet implemented. ' +
'This method will be activated when user authentication is added.'
);

return response.json();
throw new Error(
'Policy updates via API are not yet supported. ' +
'Please ensure you are using localStorage mode.'
);
}
*/

// Not yet implemented, but keeping for future use
/*
Expand Down Expand Up @@ -155,25 +154,28 @@ export class LocalStoragePolicyStore implements UserPolicyStore {
localStorage.setItem(this.STORAGE_KEY, JSON.stringify(policies));
}

// Not yet implemented, but keeping for future use
/*
async update(userId: string, policyId: string, updates: Partial<UserPolicy>): Promise<UserPolicy> {
async update(userPolicyId: string, updates: Partial<UserPolicy>): Promise<UserPolicy> {
const policies = this.getStoredPolicies();
const index = policies.findIndex(
a => a.userId === userId && a.policyId === policyId
);

// Find by userPolicy.id (the "sup-" prefixed ID), NOT policyId
const index = policies.findIndex((p) => p.id === userPolicyId);

if (index === -1) {
throw new Error('Association not found');
throw new Error(`UserPolicy with id ${userPolicyId} not found`);
}

const updated = { ...policies[index], ...updates };
// Merge updates and set timestamp
const updated: UserPolicy = {
...policies[index],
...updates,
updatedAt: new Date().toISOString(),
};

policies[index] = updated;
this.setStoredPolicies(policies);

return updated;
}
*/

// Not yet implemented, but keeping for future use
/*
Expand Down
50 changes: 26 additions & 24 deletions app/src/api/reportAssociation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export interface UserReportStore {
findByUser: (userId: string, countryId?: string) => Promise<UserReport[]>;
findById: (userId: string, reportId: string) => Promise<UserReport | null>;
findByUserReportId: (userReportId: string) => Promise<UserReport | null>;
update: (userReportId: string, updates: Partial<UserReport>) => Promise<UserReport>;
// The below are not yet implemented, but keeping for future use
// update(userId: string, reportId: string, updates: Partial<UserReport>): Promise<UserReport>;
// delete(userId: string, reportId: string): Promise<void>;
// delete(userReportId: string): Promise<void>;
}

export class ApiReportStore implements UserReportStore {
Expand Down Expand Up @@ -83,22 +83,21 @@ export class ApiReportStore implements UserReportStore {
return UserReportAdapter.fromApiResponse(apiData);
}

// Not yet implemented, but keeping for future use
/*
async update(userId: string, reportId: string, updates: Partial<UserReport>): Promise<UserReport> {
const response = await fetch(`/api/user-report-associations/${userId}/${reportId}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(updates),
});
async update(_userReportId: string, _updates: Partial<UserReport>): Promise<UserReport> {
// TODO: Implement when backend API endpoint is available
// Expected endpoint: PUT /api/user-report-associations/:userReportId
// Expected payload: UserReportUpdatePayload (to be created)

if (!response.ok) {
throw new Error('Failed to update association');
}
console.warn(
'[ApiReportStore.update] API endpoint not yet implemented. ' +
'This method will be activated when user authentication is added.'
);

return response.json();
throw new Error(
'Report updates via API are not yet supported. ' +
'Please ensure you are using localStorage mode.'
);
}
*/

// Not yet implemented, but keeping for future use
/*
Expand Down Expand Up @@ -168,25 +167,28 @@ export class LocalStorageReportStore implements UserReportStore {
localStorage.setItem(this.STORAGE_KEY, JSON.stringify(reports));
}

// Not yet implemented, but keeping for future use
/*
async update(userId: string, reportId: string, updates: Partial<UserReport>): Promise<UserReport> {
async update(userReportId: string, updates: Partial<UserReport>): Promise<UserReport> {
const reports = this.getStoredReports();
const index = reports.findIndex(
a => a.userId === userId && a.reportId === reportId
);

// Find by userReport.id (the "sur-" prefixed ID), NOT reportId
const index = reports.findIndex((r) => r.id === userReportId);

if (index === -1) {
throw new Error('Association not found');
throw new Error(`UserReport with id ${userReportId} not found`);
}

const updated = { ...reports[index], ...updates };
// Merge updates and set timestamp
const updated: UserReport = {
...reports[index],
...updates,
updatedAt: new Date().toISOString(),
};

reports[index] = updated;
this.setStoredReports(reports);

return updated;
}
*/

// Not yet implemented, but keeping for future use
/*
Expand Down
Loading
Loading