convert all remaining DB writes & reads to SQL (with successful registration & claim)

This commit is contained in:
2025-05-27 21:07:24 -06:00
parent f0d8fdf98c
commit 8092d1c576
67 changed files with 1200 additions and 266 deletions

View File

@@ -138,11 +138,19 @@ import ContactNameDialog from "../components/ContactNameDialog.vue";
import QuickNav from "../components/QuickNav.vue";
import TopMessage from "../components/TopMessage.vue";
import InviteDialog from "../components/InviteDialog.vue";
import { APP_SERVER, AppString, NotificationIface } from "../constants/app";
import {
APP_SERVER,
AppString,
NotificationIface,
USE_DEXIE_DB,
} from "../constants/app";
import { db, retrieveSettingsForActiveAccount } from "../db/index";
import { Contact } from "../db/tables/contacts";
import * as databaseUtil from "../db/databaseUtil";
import { createInviteJwt, getHeaders } from "../libs/endorserServer";
import { PlatformServiceFactory } from "../services/PlatformServiceFactory";
import { logger } from "../utils/logger";
interface Invite {
inviteIdentifier: string;
expiresAt: string;
@@ -168,8 +176,11 @@ export default class InviteOneView extends Vue {
async mounted() {
try {
await db.open();
const settings = await retrieveSettingsForActiveAccount();
let settings = await databaseUtil.retrieveSettingsForActiveAccount();
if (USE_DEXIE_DB) {
await db.open();
settings = await retrieveSettingsForActiveAccount();
}
this.activeDid = settings.activeDid || "";
this.apiServer = settings.apiServer || "";
this.isRegistered = !!settings.isRegistered;
@@ -181,7 +192,16 @@ export default class InviteOneView extends Vue {
);
this.invites = response.data.data;
const baseContacts: Contact[] = await db.contacts.toArray();
const platformService = PlatformServiceFactory.getInstance();
const queryResult = await platformService.dbQuery(
"SELECT * FROM contacts",
);
let baseContacts = databaseUtil.mapQueryResultToValues(
queryResult,
) as unknown as Contact[];
if (USE_DEXIE_DB) {
baseContacts = await db.contacts.toArray();
}
for (const invite of this.invites) {
const contact = baseContacts.find(
(contact) => contact.did === invite.redeemedBy,
@@ -328,18 +348,27 @@ export default class InviteOneView extends Vue {
);
}
addNewContact(did: string, notes: string) {
async addNewContact(did: string, notes: string) {
(this.$refs.contactNameDialog as ContactNameDialog).open(
"To Whom Did You Send The Invite?",
"Their name will be added to your contact list.",
(name) => {
async (name) => {
// the person obviously registered themselves and this user already granted visibility, so we just add them
const contact = {
did: did,
name: name,
registered: true,
};
db.contacts.add(contact);
const platformService = PlatformServiceFactory.getInstance();
const columns = Object.keys(contact);
const values = Object.values(contact);
const placeholders = values.map(() => "?").join(", ");
const sql = `INSERT INTO contacts (${columns.join(", ")}) VALUES (${placeholders})`;
await platformService.dbExec(sql, values);
if (USE_DEXIE_DB) {
await db.contacts.add(contact);
}
this.contactsRedeemed[did] = contact;
this.$notify(
{