forked from trent_larson/crowd-funder-for-time-pwa
refactor(settings): simplify $getSettings to $getMasterSettings
- Rename $getSettings to $getMasterSettings for clarity - Remove unused account-specific logic (never called with accountDid) - Simplify method signature by removing unused key parameter - Update all 8 call sites and interface definitions - Maintain backward compatibility for all existing functionality All calls to $getSettings used MASTER_SETTINGS_KEY, so the complex branching logic for account-specific settings was unnecessary.
This commit is contained in:
@@ -437,30 +437,18 @@ export const PlatformServiceMixin = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Utility method for retrieving and parsing settings
|
||||
* Utility method for retrieving master settings
|
||||
* Common pattern used across many components
|
||||
*/
|
||||
async $getSettings(
|
||||
key: string,
|
||||
async $getMasterSettings(
|
||||
fallback: Settings | null = null,
|
||||
): Promise<Settings | null> {
|
||||
try {
|
||||
// FIXED: Use specific queries instead of ambiguous OR condition
|
||||
let result;
|
||||
|
||||
// Check if this is a master settings key (numeric or "1")
|
||||
if (key === MASTER_SETTINGS_KEY || key === "1" || !isNaN(Number(key))) {
|
||||
// Master settings: query by id
|
||||
result = await this.$dbQuery("SELECT * FROM settings WHERE id = ?", [
|
||||
key,
|
||||
]);
|
||||
} else {
|
||||
// Account settings: query by accountDid
|
||||
result = await this.$dbQuery(
|
||||
"SELECT * FROM settings WHERE accountDid = ?",
|
||||
[key],
|
||||
);
|
||||
}
|
||||
// Master settings: query by id
|
||||
const result = await this.$dbQuery(
|
||||
"SELECT * FROM settings WHERE id = ?",
|
||||
[MASTER_SETTINGS_KEY],
|
||||
);
|
||||
|
||||
if (!result?.values?.length) {
|
||||
return fallback;
|
||||
@@ -484,8 +472,7 @@ export const PlatformServiceMixin = {
|
||||
|
||||
return settings;
|
||||
} catch (error) {
|
||||
logger.error(`[Settings Trace] ❌ Failed to get settings:`, {
|
||||
key,
|
||||
logger.error(`[Settings Trace] ❌ Failed to get master settings:`, {
|
||||
error,
|
||||
});
|
||||
return fallback;
|
||||
@@ -503,10 +490,7 @@ export const PlatformServiceMixin = {
|
||||
): Promise<Settings> {
|
||||
try {
|
||||
// Get default settings
|
||||
const defaultSettings = await this.$getSettings(
|
||||
defaultKey,
|
||||
defaultFallback,
|
||||
);
|
||||
const defaultSettings = await this.$getMasterSettings(defaultFallback);
|
||||
|
||||
// If no account DID, return defaults
|
||||
if (!accountDid) {
|
||||
@@ -769,7 +753,7 @@ export const PlatformServiceMixin = {
|
||||
* @returns Fresh settings object from database
|
||||
*/
|
||||
async $settings(defaults: Settings = {}): Promise<Settings> {
|
||||
const settings = await this.$getSettings(MASTER_SETTINGS_KEY, defaults);
|
||||
const settings = await this.$getMasterSettings(defaults);
|
||||
|
||||
if (!settings) {
|
||||
return defaults;
|
||||
@@ -802,10 +786,7 @@ export const PlatformServiceMixin = {
|
||||
): Promise<Settings> {
|
||||
try {
|
||||
// Get default settings first
|
||||
const defaultSettings = await this.$getSettings(
|
||||
MASTER_SETTINGS_KEY,
|
||||
defaults,
|
||||
);
|
||||
const defaultSettings = await this.$getMasterSettings(defaults);
|
||||
|
||||
if (!defaultSettings) {
|
||||
return defaults;
|
||||
@@ -1590,10 +1571,7 @@ export const PlatformServiceMixin = {
|
||||
async $debugMergedSettings(did: string): Promise<void> {
|
||||
try {
|
||||
// Get default settings
|
||||
const defaultSettings = await this.$getSettings(
|
||||
MASTER_SETTINGS_KEY,
|
||||
{},
|
||||
);
|
||||
const defaultSettings = await this.$getMasterSettings({});
|
||||
logger.info(
|
||||
`[PlatformServiceMixin] Default settings:`,
|
||||
defaultSettings,
|
||||
@@ -1640,10 +1618,7 @@ export interface IPlatformServiceMixin {
|
||||
): Promise<QueryExecResult | undefined>;
|
||||
$dbExec(sql: string, params?: unknown[]): Promise<DatabaseExecResult>;
|
||||
$dbGetOneRow(sql: string, params?: unknown[]): Promise<unknown[] | undefined>;
|
||||
$getSettings(
|
||||
key: string,
|
||||
fallback?: Settings | null,
|
||||
): Promise<Settings | null>;
|
||||
$getMasterSettings(fallback?: Settings | null): Promise<Settings | null>;
|
||||
$getMergedSettings(
|
||||
defaultKey: string,
|
||||
accountDid?: string,
|
||||
@@ -1765,10 +1740,7 @@ declare module "@vue/runtime-core" {
|
||||
sql: string,
|
||||
params?: unknown[],
|
||||
): Promise<unknown[] | undefined>;
|
||||
$getSettings(
|
||||
key: string,
|
||||
defaults?: Settings | null,
|
||||
): Promise<Settings | null>;
|
||||
$getMasterSettings(defaults?: Settings | null): Promise<Settings | null>;
|
||||
$getMergedSettings(
|
||||
key: string,
|
||||
did?: string,
|
||||
|
||||
@@ -124,7 +124,7 @@ import {
|
||||
NOTIFY_CONFIRMATION_RESTRICTION,
|
||||
} from "../constants/notifications";
|
||||
import { Contact } from "../db/tables/contacts";
|
||||
import { MASTER_SETTINGS_KEY } from "../db/tables/settings";
|
||||
|
||||
import { GiveSummaryRecord, GiveActionClaim } from "../interfaces";
|
||||
import { AgreeActionClaim } from "../interfaces/claims";
|
||||
import {
|
||||
@@ -223,7 +223,7 @@ export default class ContactAmountssView extends Vue {
|
||||
const contact = await this.$getContact(contactDid);
|
||||
this.contact = contact;
|
||||
|
||||
const settings = await this.$getSettings(MASTER_SETTINGS_KEY);
|
||||
const settings = await this.$getMasterSettings();
|
||||
this.activeDid = settings?.activeDid || "";
|
||||
this.apiServer = settings?.apiServer || "";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user