Browse Source

refactor(services): align Capacitor and Web platform services with active_identity architecture

- Update CapacitorPlatformService.updateDefaultSettings() to use active_identity table instead of hard-coded id=1
- Update CapacitorPlatformService.retrieveSettingsForActiveAccount() to query by accountDid from active_identity
- Add getActiveIdentity() method to CapacitorPlatformService for consistency with WebPlatformService
- Update WebPlatformService.retrieveSettingsForActiveAccount() to match CapacitorPlatformService pattern
- Both services now consistently use active_identity table instead of legacy MASTER_SETTINGS_KEY approach
- Maintains backward compatibility with databaseUtil.ts for PWA migration support

Technical details:
- CapacitorPlatformService: Fixed hard-coded WHERE id = 1 → WHERE accountDid = ?
- WebPlatformService: Fixed retrieval pattern to match new architecture
- Platform services now aligned with migration 004 active_identity table schema
- databaseUtil.ts remains unchanged for PWA-to-SQLite migration bridge
pull/204/head
Matthew Raymer 2 weeks ago
parent
commit
7432525f4c
  1. 38
      src/services/platforms/CapacitorPlatformService.ts
  2. 14
      src/services/platforms/WebPlatformService.ts

38
src/services/platforms/CapacitorPlatformService.ts

@ -1343,10 +1343,21 @@ export class CapacitorPlatformService implements PlatformService {
async updateDefaultSettings(
settings: Record<string, unknown>,
): Promise<void> {
// Get current active DID and update that identity's settings
const activeIdentity = await this.getActiveIdentity();
const activeDid = activeIdentity.activeDid;
if (!activeDid) {
logger.warn(
"[CapacitorPlatformService] No active DID found, cannot update default settings",
);
return;
}
const keys = Object.keys(settings);
const setClause = keys.map((key) => `${key} = ?`).join(", ");
const sql = `UPDATE settings SET ${setClause} WHERE id = 1`;
const params = keys.map((key) => settings[key]);
const sql = `UPDATE settings SET ${setClause} WHERE accountDid = ?`;
const params = [...keys.map((key) => settings[key]), activeDid];
await this.dbExec(sql, params);
}
@ -1357,6 +1368,15 @@ export class CapacitorPlatformService implements PlatformService {
);
}
async getActiveIdentity(): Promise<{ activeDid: string }> {
const result = await this.dbQuery(
"SELECT activeDid FROM active_identity WHERE id = 1",
);
return {
activeDid: (result?.values?.[0]?.[0] as string) || "",
};
}
async insertNewDidIntoSettings(did: string): Promise<void> {
// Import constants dynamically to avoid circular dependencies
const { DEFAULT_ENDORSER_API_SERVER, DEFAULT_PARTNER_API_SERVER } =
@ -1385,7 +1405,15 @@ export class CapacitorPlatformService implements PlatformService {
string,
unknown
> | null> {
const result = await this.dbQuery("SELECT * FROM settings WHERE id = 1");
// Get current active DID from active_identity table
const activeIdentity = await this.getActiveIdentity();
const activeDid = activeIdentity.activeDid;
if (!activeDid) {
return null;
}
const result = await this.dbQuery("SELECT * FROM settings WHERE accountDid = ?", [activeDid]);
if (result?.values?.[0]) {
// Convert the row to an object
const row = result.values[0];
@ -1393,8 +1421,8 @@ export class CapacitorPlatformService implements PlatformService {
const settings: Record<string, unknown> = {};
columns.forEach((column, index) => {
if (column !== "id") {
// Exclude the id column
if (column !== "id" && column !== "accountDid") {
// Exclude the id and accountDid columns
settings[column] = row[index];
}
});

14
src/services/platforms/WebPlatformService.ts

@ -753,7 +753,15 @@ export class WebPlatformService implements PlatformService {
string,
unknown
> | null> {
const result = await this.dbQuery("SELECT * FROM settings WHERE id = 1");
// Get current active DID from active_identity table
const activeIdentity = await this.getActiveIdentity();
const activeDid = activeIdentity.activeDid;
if (!activeDid) {
return null;
}
const result = await this.dbQuery("SELECT * FROM settings WHERE accountDid = ?", [activeDid]);
if (result?.values?.[0]) {
// Convert the row to an object
const row = result.values[0];
@ -761,8 +769,8 @@ export class WebPlatformService implements PlatformService {
const settings: Record<string, unknown> = {};
columns.forEach((column, index) => {
if (column !== "id") {
// Exclude the id column
if (column !== "id" && column !== "accountDid") {
// Exclude the id and accountDid columns
settings[column] = row[index];
}
});

Loading…
Cancel
Save