forked from trent_larson/crowd-funder-for-time-pwa
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
This commit is contained in:
@@ -1343,10 +1343,21 @@ export class CapacitorPlatformService implements PlatformService {
|
|||||||
async updateDefaultSettings(
|
async updateDefaultSettings(
|
||||||
settings: Record<string, unknown>,
|
settings: Record<string, unknown>,
|
||||||
): Promise<void> {
|
): 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 keys = Object.keys(settings);
|
||||||
const setClause = keys.map((key) => `${key} = ?`).join(", ");
|
const setClause = keys.map((key) => `${key} = ?`).join(", ");
|
||||||
const sql = `UPDATE settings SET ${setClause} WHERE id = 1`;
|
const sql = `UPDATE settings SET ${setClause} WHERE accountDid = ?`;
|
||||||
const params = keys.map((key) => settings[key]);
|
const params = [...keys.map((key) => settings[key]), activeDid];
|
||||||
await this.dbExec(sql, params);
|
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> {
|
async insertNewDidIntoSettings(did: string): Promise<void> {
|
||||||
// Import constants dynamically to avoid circular dependencies
|
// Import constants dynamically to avoid circular dependencies
|
||||||
const { DEFAULT_ENDORSER_API_SERVER, DEFAULT_PARTNER_API_SERVER } =
|
const { DEFAULT_ENDORSER_API_SERVER, DEFAULT_PARTNER_API_SERVER } =
|
||||||
@@ -1385,7 +1405,15 @@ export class CapacitorPlatformService implements PlatformService {
|
|||||||
string,
|
string,
|
||||||
unknown
|
unknown
|
||||||
> | null> {
|
> | 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]) {
|
if (result?.values?.[0]) {
|
||||||
// Convert the row to an object
|
// Convert the row to an object
|
||||||
const row = result.values[0];
|
const row = result.values[0];
|
||||||
@@ -1393,8 +1421,8 @@ export class CapacitorPlatformService implements PlatformService {
|
|||||||
const settings: Record<string, unknown> = {};
|
const settings: Record<string, unknown> = {};
|
||||||
|
|
||||||
columns.forEach((column, index) => {
|
columns.forEach((column, index) => {
|
||||||
if (column !== "id") {
|
if (column !== "id" && column !== "accountDid") {
|
||||||
// Exclude the id column
|
// Exclude the id and accountDid columns
|
||||||
settings[column] = row[index];
|
settings[column] = row[index];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -753,7 +753,15 @@ export class WebPlatformService implements PlatformService {
|
|||||||
string,
|
string,
|
||||||
unknown
|
unknown
|
||||||
> | null> {
|
> | 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]) {
|
if (result?.values?.[0]) {
|
||||||
// Convert the row to an object
|
// Convert the row to an object
|
||||||
const row = result.values[0];
|
const row = result.values[0];
|
||||||
@@ -761,8 +769,8 @@ export class WebPlatformService implements PlatformService {
|
|||||||
const settings: Record<string, unknown> = {};
|
const settings: Record<string, unknown> = {};
|
||||||
|
|
||||||
columns.forEach((column, index) => {
|
columns.forEach((column, index) => {
|
||||||
if (column !== "id") {
|
if (column !== "id" && column !== "accountDid") {
|
||||||
// Exclude the id column
|
// Exclude the id and accountDid columns
|
||||||
settings[column] = row[index];
|
settings[column] = row[index];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user