forked from jsnbuchanan/crowd-funder-for-time-pwa
fix: export contactMethods as JSON arrays instead of strings
- Fixed contactsToExportJson to properly handle contactMethods as arrays - Fixed contactToCsvLine to correctly stringify contactMethods arrays - Removed unused parseJsonField function (consolidated with PlatformServiceMixin) - Resolves issue where contact backup exports showed contactMethods as strings instead of JSON arrays
This commit is contained in:
@@ -35,17 +35,6 @@ import { IIdentifier } from "@veramo/core";
|
|||||||
import { DEFAULT_ROOT_DERIVATION_PATH } from "./crypto";
|
import { DEFAULT_ROOT_DERIVATION_PATH } from "./crypto";
|
||||||
|
|
||||||
// Consolidate this with src/utils/PlatformServiceMixin._parseJsonField
|
// Consolidate this with src/utils/PlatformServiceMixin._parseJsonField
|
||||||
function parseJsonField<T>(value: unknown, defaultValue: T): T {
|
|
||||||
if (typeof value === "string") {
|
|
||||||
try {
|
|
||||||
return JSON.parse(value);
|
|
||||||
} catch {
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (value as T) || defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
function mapQueryResultToValues(
|
function mapQueryResultToValues(
|
||||||
record: { columns: string[]; values: unknown[][] } | undefined,
|
record: { columns: string[]; values: unknown[][] } | undefined,
|
||||||
): Array<Record<string, unknown>> {
|
): Array<Record<string, unknown>> {
|
||||||
@@ -806,7 +795,7 @@ export const contactToCsvLine = (contact: Contact): string => {
|
|||||||
|
|
||||||
// Handle contactMethods array by stringifying it
|
// Handle contactMethods array by stringifying it
|
||||||
const contactMethodsStr = contact.contactMethods
|
const contactMethodsStr = contact.contactMethods
|
||||||
? escapeField(JSON.stringify(parseJsonField(contact.contactMethods, [])))
|
? escapeField(JSON.stringify(contact.contactMethods))
|
||||||
: "";
|
: "";
|
||||||
|
|
||||||
const fields = [
|
const fields = [
|
||||||
@@ -918,7 +907,7 @@ export const contactsToExportJson = (contacts: Contact[]): DatabaseExport => {
|
|||||||
contact,
|
contact,
|
||||||
);
|
);
|
||||||
exContact.contactMethods = contact.contactMethods
|
exContact.contactMethods = contact.contactMethods
|
||||||
? JSON.stringify(parseJsonField(contact.contactMethods, []))
|
? JSON.stringify(contact.contactMethods)
|
||||||
: undefined;
|
: undefined;
|
||||||
return exContact;
|
return exContact;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user