forked from trent_larson/crowd-funder-for-time-pwa
feat(api)!: fix $getActiveIdentity return type for ActiveDid migration
Update $getActiveIdentity() method to return { activeDid: string } instead
of full ActiveIdentity object. Add validation to ensure activeDid exists
in accounts table and clear corrupted values. Update migration plan to
reflect completed first step of API layer implementation.
- Change return type from Promise<ActiveIdentity> to Promise<{ activeDid: string }>
- Add account validation with automatic corruption cleanup
- Simplify query to only select activeDid field
- Improve error handling to return empty string instead of throwing
- Update migration plan documentation with current status
This commit is contained in:
@@ -553,33 +553,41 @@ export const PlatformServiceMixin = {
|
||||
* Get active identity from the new active_identity table
|
||||
* This replaces the activeDid field in settings for better architecture
|
||||
*/
|
||||
async $getActiveIdentity(): Promise<ActiveIdentity> {
|
||||
async $getActiveIdentity(): Promise<{ activeDid: string }> {
|
||||
try {
|
||||
const result = await this.$dbQuery(
|
||||
"SELECT id, activeDid, lastUpdated FROM active_identity WHERE id = 1",
|
||||
"SELECT activeDid FROM active_identity WHERE id = 1",
|
||||
);
|
||||
|
||||
if (result?.values?.length) {
|
||||
const [id, activeDid, lastUpdated] = result.values[0];
|
||||
return {
|
||||
id: id as number,
|
||||
activeDid: activeDid as string,
|
||||
lastUpdated: lastUpdated as string,
|
||||
};
|
||||
const activeDid = result.values[0][0] as string;
|
||||
|
||||
// Validate activeDid exists in accounts
|
||||
if (activeDid) {
|
||||
const accountExists = await this.$dbQuery(
|
||||
"SELECT did FROM accounts WHERE did = ?",
|
||||
[activeDid]
|
||||
);
|
||||
|
||||
if (accountExists?.values?.length) {
|
||||
return { activeDid };
|
||||
} else {
|
||||
// Clear corrupted activeDid
|
||||
await this.$dbExec(
|
||||
"UPDATE active_identity SET activeDid = '', lastUpdated = datetime('now') WHERE id = 1"
|
||||
);
|
||||
return { activeDid: "" };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Return default if no record exists
|
||||
return {
|
||||
id: 1,
|
||||
activeDid: "",
|
||||
lastUpdated: new Date().toISOString(),
|
||||
};
|
||||
|
||||
return { activeDid: "" };
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
"[PlatformServiceMixin] Error getting active identity:",
|
||||
error,
|
||||
);
|
||||
throw error;
|
||||
return { activeDid: "" };
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user