forked from jsnbuchanan/crowd-funder-for-time-pwa
fix: preserve contact methods and notes in export/import workflow
- Fix contactMethods not being exported (was checking for string instead of array) - Add missing notes and iViewContent fields to $insertContact method - Normalize empty strings to null when saving contacts in ContactEditView This ensures contact data integrity is maintained during export/import operations.
This commit is contained in:
@@ -257,12 +257,30 @@ export default class DataExportSection extends Vue {
|
||||
// first remove the contactMethods field, mostly to cast to a clear type (that will end up with JSON objects)
|
||||
const exContact: Contact = R.omit(["contactMethods"], contact);
|
||||
// now add contactMethods as a true array of ContactMethod objects
|
||||
exContact.contactMethods = contact.contactMethods
|
||||
? typeof contact.contactMethods === "string" &&
|
||||
contact.contactMethods.trim() !== ""
|
||||
? JSON.parse(contact.contactMethods)
|
||||
: []
|
||||
: [];
|
||||
// $contacts() returns normalized contacts where contactMethods is already an array,
|
||||
// but we handle both array and string cases for robustness
|
||||
if (contact.contactMethods) {
|
||||
if (Array.isArray(contact.contactMethods)) {
|
||||
// Already an array, use it directly
|
||||
exContact.contactMethods = contact.contactMethods;
|
||||
} else {
|
||||
// Check if it's a string that needs parsing (shouldn't happen with normalized contacts, but handle for robustness)
|
||||
const contactMethodsValue = contact.contactMethods as unknown;
|
||||
if (
|
||||
typeof contactMethodsValue === "string" &&
|
||||
contactMethodsValue.trim() !== ""
|
||||
) {
|
||||
// String that needs parsing
|
||||
exContact.contactMethods = JSON.parse(contactMethodsValue);
|
||||
} else {
|
||||
// Invalid data, use empty array
|
||||
exContact.contactMethods = [];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// No contactMethods, use empty array
|
||||
exContact.contactMethods = [];
|
||||
}
|
||||
return exContact;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user