@ -60,9 +60,11 @@ backup and database export, with platform-specific download instructions. * *
< script lang = "ts" >
import { Component , Prop , Vue } from "vue-facing-decorator" ;
import * as R from "ramda" ;
import { AppString , NotificationIface } from "../constants/app" ;
import { Contact } from "../db/tables/contacts" ;
import { Contact , ContactMaybeWithJsonStrings , ContactMethod } from "../db/tables/contacts" ;
import * as databaseUtil from "../db/databaseUtil" ;
import { logger } from "../utils/logger" ;
@ -72,6 +74,7 @@ import {
PlatformCapabilities ,
} from "../services/PlatformService" ;
import { contactsToExportJson } from "../libs/util" ;
import { parseJsonField } from "../db/databaseUtil" ;
/ * *
* @ vue - component
@ -133,13 +136,13 @@ export default class DataExportSection extends Vue {
* /
public async exportDatabase ( ) {
try {
let allContacts : Contact [ ] = [ ] ;
let allDb Contacts : ContactMaybeWithJsonStrings [ ] = [ ] ;
const platformService = PlatformServiceFactory . getInstance ( ) ;
const result = await platformService . dbQuery ( ` SELECT * FROM contacts ` ) ;
if ( result ) {
allContacts = databaseUtil . mapQueryResultToValues (
allDb Contacts = databaseUtil . mapQueryResultToValues (
result ,
) as unknown as Contact [ ] ;
) as unknown as ContactMaybeWithJsonStrings [ ] ;
}
/ / i f ( U S E _ D E X I E _ D B ) {
/ / a w a i t d b . o p e n ( ) ;
@ -147,6 +150,19 @@ export default class DataExportSection extends Vue {
/ / }
/ / C o n v e r t c o n t a c t s t o e x p o r t f o r m a t
const allContacts : Contact [ ] = allDbContacts . map ( ( contact ) => {
/ / f i r s t r e m o v e t h e c o n t a c t M e t h o d s f i e l d , m o s t l y t o c a s t t o a c l e a r t y p e ( t h a t w i l l e n d u p w i t h J S O N o b j e c t s )
const exContact : Contact = R . omit (
[ "contactMethods" ] ,
contact ,
) ;
/ / n o w a d d c o n t a c t M e t h o d s a s a t r u e a r r a y o f C o n t a c t M e t h o d o b j e c t s
exContact . contactMethods = contact . contactMethods
? parseJsonField ( contact . contactMethods , [ ] as Array < ContactMethod > )
: undefined ;
return exContact ;
} ) ;
const exportData = contactsToExportJson ( allContacts ) ;
const jsonStr = JSON . stringify ( exportData , null , 2 ) ;
const blob = new Blob ( [ jsonStr ] , { type : "application/json" } ) ;