forked from jsnbuchanan/crowd-funder-for-time-pwa
add SQL DB access to everywhere we are using the DB, up to the "C" files
This commit is contained in:
@@ -138,9 +138,11 @@ import { RouteLocationNormalizedLoaded, Router } from "vue-router";
|
||||
|
||||
import QuickNav from "../components/QuickNav.vue";
|
||||
import TopMessage from "../components/TopMessage.vue";
|
||||
import { AppString, NotificationIface } from "../constants/app";
|
||||
import { AppString, NotificationIface, USE_DEXIE_DB } from "../constants/app";
|
||||
import { db } from "../db/index";
|
||||
import { Contact, ContactMethod } from "../db/tables/contacts";
|
||||
import * as databaseUtil from "../db/databaseUtil";
|
||||
import { PlatformServiceFactory } from "@/services/PlatformServiceFactory";
|
||||
|
||||
/**
|
||||
* Contact Edit View Component
|
||||
@@ -188,7 +190,7 @@ export default class ContactEditView extends Vue {
|
||||
$router!: Router;
|
||||
|
||||
/** Current contact data */
|
||||
contact: Contact = {
|
||||
contact: Contact | undefined = {
|
||||
did: "",
|
||||
name: "",
|
||||
notes: "",
|
||||
@@ -220,7 +222,21 @@ export default class ContactEditView extends Vue {
|
||||
*/
|
||||
async created() {
|
||||
const contactDid = this.$route.params.did;
|
||||
const contact = await db.contacts.get(contactDid || "");
|
||||
const platformService = PlatformServiceFactory.getInstance();
|
||||
const dbContact = await platformService.dbQuery(
|
||||
"SELECT * FROM contacts WHERE did = ?",
|
||||
[contactDid],
|
||||
);
|
||||
let contact: Contact | undefined = databaseUtil.mapQueryResultToValues(
|
||||
dbContact,
|
||||
)[0] as unknown as Contact;
|
||||
contact.contactMethods = JSON.parse(
|
||||
(contact?.contactMethods as unknown as string) || "[]",
|
||||
);
|
||||
if (USE_DEXIE_DB) {
|
||||
await db.open();
|
||||
contact = await db.contacts.get(contactDid || "");
|
||||
}
|
||||
if (contact) {
|
||||
this.contact = contact;
|
||||
this.contactName = contact.name || "";
|
||||
@@ -322,12 +338,24 @@ export default class ContactEditView extends Vue {
|
||||
}
|
||||
|
||||
// Save to database
|
||||
await db.contacts.update(this.contact.did, {
|
||||
name: this.contactName,
|
||||
notes: this.contactNotes,
|
||||
contactMethods: contactMethods,
|
||||
});
|
||||
|
||||
const platformService = PlatformServiceFactory.getInstance();
|
||||
const contactMethodsString = JSON.stringify(contactMethods);
|
||||
await platformService.dbExec(
|
||||
"UPDATE contacts SET name = ?, notes = ?, contactMethods = ? WHERE did = ?",
|
||||
[
|
||||
this.contactName,
|
||||
this.contactNotes,
|
||||
contactMethodsString,
|
||||
this.contact?.did || "",
|
||||
],
|
||||
);
|
||||
if (USE_DEXIE_DB) {
|
||||
await db.contacts.update(this.contact?.did || "", {
|
||||
name: this.contactName,
|
||||
notes: this.contactNotes,
|
||||
contactMethods: contactMethods,
|
||||
});
|
||||
}
|
||||
// Notify success and redirect
|
||||
this.$notify({
|
||||
group: "alert",
|
||||
@@ -336,7 +364,7 @@ export default class ContactEditView extends Vue {
|
||||
text: "The contact info has been updated successfully.",
|
||||
});
|
||||
(this.$router as Router).push({
|
||||
path: "/did/" + encodeURIComponent(this.contact.did),
|
||||
path: "/did/" + encodeURIComponent(this.contact?.did || ""),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user