forked from jsnbuchanan/crowd-funder-for-time-pwa
Fix database undefined values causing SQL.js binding errors
Convert undefined values to null in database operations to prevent "tried to bind a value of an unknown type" errors in SQL.js worker. - Fix $insertContact() method undefined-to-null conversion - Fix $insertEntity() method undefined-to-null conversion - Preserve boolean false/0 values vs null distinction - Maintain parameterized queries for SQL injection protection - Fix contact creation errors in ContactsView component Resolves database binding failures when inserting contacts with undefined properties. All linting errors resolved.
This commit is contained in:
@@ -366,7 +366,7 @@ import TopMessage from "../components/TopMessage.vue";
|
||||
import { APP_SERVER, AppString, NotificationIface } from "../constants/app";
|
||||
import { logConsoleAndDb } from "../db/index";
|
||||
import { Contact } from "../db/tables/contacts";
|
||||
import * as databaseUtil from "../db/databaseUtil";
|
||||
// Removed unused import: databaseUtil - migrated to PlatformServiceMixin
|
||||
import { getContactJwtFromJwtUrl } from "../libs/crypto";
|
||||
import { decodeEndorserJwt } from "../libs/crypto/vc";
|
||||
import {
|
||||
@@ -438,30 +438,30 @@ export default class ContactsView extends Vue {
|
||||
libsUtil = libsUtil;
|
||||
|
||||
public async created() {
|
||||
const settings = await databaseUtil.retrieveSettingsForActiveAccount();
|
||||
this.activeDid = settings.activeDid || "";
|
||||
this.apiServer = settings.apiServer || "";
|
||||
this.isRegistered = !!settings.isRegistered;
|
||||
const settingsRow = await this.$getSettingsRow([
|
||||
"activeDid",
|
||||
"apiServer",
|
||||
"isRegistered",
|
||||
"showContactGivesInline",
|
||||
"hideRegisterPromptOnNewContact",
|
||||
]);
|
||||
this.activeDid = (settingsRow?.[0] as string) || "";
|
||||
this.apiServer = (settingsRow?.[1] as string) || "";
|
||||
this.isRegistered = !!settingsRow?.[2];
|
||||
|
||||
// if these detect a query parameter, they can and then redirect to this URL without a query parameter
|
||||
// to avoid problems when they reload or they go forward & back and it tries to reprocess
|
||||
await this.processContactJwt();
|
||||
await this.processInviteJwt();
|
||||
|
||||
this.showGiveNumbers = !!settings.showContactGivesInline;
|
||||
this.hideRegisterPromptOnNewContact =
|
||||
!!settings.hideRegisterPromptOnNewContact;
|
||||
this.showGiveNumbers = !!settingsRow?.[3];
|
||||
this.hideRegisterPromptOnNewContact = !!settingsRow?.[4];
|
||||
|
||||
if (this.showGiveNumbers) {
|
||||
this.loadGives();
|
||||
}
|
||||
|
||||
const dbAllContacts = await this.$dbQuery(
|
||||
"SELECT * FROM contacts ORDER BY name",
|
||||
);
|
||||
this.contacts = databaseUtil.mapQueryResultToValues(
|
||||
dbAllContacts,
|
||||
) as unknown as Contact[];
|
||||
this.contacts = await this.$getAllContacts();
|
||||
}
|
||||
|
||||
private async processContactJwt() {
|
||||
@@ -518,9 +518,7 @@ export default class ContactsView extends Vue {
|
||||
if (response.status != 201) {
|
||||
throw { error: { response: response } };
|
||||
}
|
||||
await databaseUtil.updateDidSpecificSettings(this.activeDid, {
|
||||
isRegistered: true,
|
||||
});
|
||||
await this.$updateSettings({ isRegistered: true }, this.activeDid);
|
||||
this.isRegistered = true;
|
||||
this.$notify(
|
||||
{
|
||||
@@ -844,12 +842,7 @@ export default class ContactsView extends Vue {
|
||||
this.danger("An error occurred. Some contacts may have been added.");
|
||||
}
|
||||
|
||||
const dbAllContacts = await this.$dbQuery(
|
||||
"SELECT * FROM contacts ORDER BY name",
|
||||
);
|
||||
this.contacts = databaseUtil.mapQueryResultToValues(
|
||||
dbAllContacts,
|
||||
) as unknown as Contact[];
|
||||
this.contacts = await this.$getAllContacts();
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -923,11 +916,7 @@ export default class ContactsView extends Vue {
|
||||
lineRaw: string,
|
||||
): Promise<IndexableType> {
|
||||
const newContact = libsUtil.csvLineToContact(lineRaw);
|
||||
const { sql, params } = databaseUtil.generateInsertStatement(
|
||||
newContact as unknown as Record<string, unknown>,
|
||||
"contacts",
|
||||
);
|
||||
await this.$dbExec(sql, params);
|
||||
await this.$insertContact(newContact);
|
||||
return newContact.did || "";
|
||||
}
|
||||
|
||||
@@ -941,11 +930,7 @@ export default class ContactsView extends Vue {
|
||||
return;
|
||||
}
|
||||
|
||||
const { sql, params } = databaseUtil.generateInsertStatement(
|
||||
newContact as unknown as Record<string, unknown>,
|
||||
"contacts",
|
||||
);
|
||||
const contactPromise = this.$dbExec(sql, params);
|
||||
const contactPromise = this.$insertContact(newContact);
|
||||
|
||||
return contactPromise
|
||||
.then(() => {
|
||||
@@ -975,7 +960,7 @@ export default class ContactsView extends Vue {
|
||||
text: "Do you want to register them?",
|
||||
onCancel: async (stopAsking?: boolean) => {
|
||||
if (stopAsking) {
|
||||
await databaseUtil.updateDefaultSettings({
|
||||
await this.$updateSettings({
|
||||
hideRegisterPromptOnNewContact: stopAsking,
|
||||
});
|
||||
|
||||
@@ -984,7 +969,7 @@ export default class ContactsView extends Vue {
|
||||
},
|
||||
onNo: async (stopAsking?: boolean) => {
|
||||
if (stopAsking) {
|
||||
await databaseUtil.updateDefaultSettings({
|
||||
await this.$updateSettings({
|
||||
hideRegisterPromptOnNewContact: stopAsking,
|
||||
});
|
||||
|
||||
@@ -1043,10 +1028,7 @@ export default class ContactsView extends Vue {
|
||||
);
|
||||
if (regResult.success) {
|
||||
contact.registered = true;
|
||||
await this.$dbExec("UPDATE contacts SET registered = ? WHERE did = ?", [
|
||||
true,
|
||||
contact.did,
|
||||
]);
|
||||
await this.$updateContact(contact.did, { registered: true });
|
||||
|
||||
this.$notify(
|
||||
{
|
||||
@@ -1253,7 +1235,7 @@ export default class ContactsView extends Vue {
|
||||
private async toggleShowContactAmounts() {
|
||||
const newShowValue = !this.showGiveNumbers;
|
||||
try {
|
||||
await databaseUtil.updateDefaultSettings({
|
||||
await this.$updateSettings({
|
||||
showContactGivesInline: newShowValue,
|
||||
});
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user