forked from trent_larson/crowd-funder-for-time-pwa
Fix SQL abstraction in SharedPhotoView.vue
- Add missing temp table service methods (, ) - Replace raw SQL with proper service method calls - Update TypeScript interfaces for temp methods - Complete Phase 2 SQL abstraction migration - Extend migration time to 11 minutes (corrected completion)
This commit is contained in:
@@ -47,6 +47,7 @@ import type {
|
||||
import { MASTER_SETTINGS_KEY, type Settings } from "@/db/tables/settings";
|
||||
import { logger } from "@/utils/logger";
|
||||
import { Contact } from "@/db/tables/contacts";
|
||||
import { Temp } from "@/db/tables/temp";
|
||||
import { QueryExecResult, DatabaseExecResult } from "@/interfaces/database";
|
||||
import {
|
||||
generateInsertStatement,
|
||||
@@ -954,6 +955,41 @@ export const PlatformServiceMixin = {
|
||||
}
|
||||
},
|
||||
|
||||
// =================================================
|
||||
// TEMP TABLE METHODS (for temporary storage)
|
||||
// =================================================
|
||||
|
||||
/**
|
||||
* Get temporary data by ID - $getTemp()
|
||||
* Retrieves temporary data from the temp table
|
||||
* @param id Temporary storage ID
|
||||
* @returns Promise<Temp | null> Temporary data or null if not found
|
||||
*/
|
||||
async $getTemp(id: string): Promise<Temp | null> {
|
||||
try {
|
||||
return await this.$first<Temp>("SELECT * FROM temp WHERE id = ?", [id]);
|
||||
} catch (error) {
|
||||
logger.error("[PlatformServiceMixin] Error getting temp data:", error);
|
||||
return null;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Delete temporary data by ID - $deleteTemp()
|
||||
* Removes temporary data from the temp table
|
||||
* @param id Temporary storage ID
|
||||
* @returns Promise<boolean> Success status
|
||||
*/
|
||||
async $deleteTemp(id: string): Promise<boolean> {
|
||||
try {
|
||||
await this.$dbExec("DELETE FROM temp WHERE id = ?", [id]);
|
||||
return true;
|
||||
} catch (error) {
|
||||
logger.error("[PlatformServiceMixin] Error deleting temp data:", error);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Generic entity insertion - $insertEntity()
|
||||
* Eliminates verbose INSERT patterns for any entity
|
||||
@@ -1261,6 +1297,8 @@ export interface IPlatformServiceMixin {
|
||||
did: string,
|
||||
settings: Partial<Settings>,
|
||||
): Promise<boolean>;
|
||||
$getTemp(id: string): Promise<Temp | null>;
|
||||
$deleteTemp(id: string): Promise<boolean>;
|
||||
|
||||
// Logging methods
|
||||
$log(message: string, level?: string): Promise<void>;
|
||||
@@ -1381,6 +1419,8 @@ declare module "@vue/runtime-core" {
|
||||
did: string,
|
||||
settings: Partial<Settings>,
|
||||
): Promise<boolean>;
|
||||
$getTemp(id: string): Promise<Temp | null>;
|
||||
$deleteTemp(id: string): Promise<boolean>;
|
||||
|
||||
// Logging methods
|
||||
$log(message: string, level?: string): Promise<void>;
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
Migration Status: ✅ Complete Enhanced Triple Migration Pattern
|
||||
- Phase 1: Database Migration (PlatformServiceMixin) ✅
|
||||
- Phase 2: SQL Abstraction ($dbQuery, $dbExec, $accountSettings, $updateSettings) ✅
|
||||
- Phase 2: SQL Abstraction ($getTemp, $deleteTemp, $accountSettings, $updateSettings) ✅
|
||||
- Phase 3: Notification Migration (3 constants, helper methods) ✅
|
||||
- Phase 4: Template Streamlining (Simple template) ✅
|
||||
|
||||
@@ -119,7 +119,7 @@ import {
|
||||
import { accessToken } from "../libs/crypto";
|
||||
import { base64ToBlob, SHARED_PHOTO_BASE64_KEY } from "../libs/util";
|
||||
import { logger } from "../utils/logger";
|
||||
import { Temp } from "@/db/tables/temp";
|
||||
|
||||
import { PlatformServiceMixin } from "@/utils/PlatformServiceMixin";
|
||||
import { createNotifyHelpers, TIMEOUTS } from "@/utils/notify";
|
||||
import {
|
||||
@@ -178,17 +178,13 @@ export default class SharedPhotoView extends Vue {
|
||||
const settings = await this.$accountSettings();
|
||||
this.activeDid = settings.activeDid;
|
||||
|
||||
const temp = await this.$first<Temp>("SELECT * FROM temp WHERE id = ?", [
|
||||
SHARED_PHOTO_BASE64_KEY,
|
||||
]);
|
||||
const temp = await this.$getTemp(SHARED_PHOTO_BASE64_KEY);
|
||||
const imageB64 = temp?.blobB64 as string;
|
||||
if (temp) {
|
||||
this.imageBlob = base64ToBlob(imageB64);
|
||||
|
||||
// clear the temp image
|
||||
await this.$dbExec("DELETE FROM temp WHERE id = ?", [
|
||||
SHARED_PHOTO_BASE64_KEY,
|
||||
]);
|
||||
await this.$deleteTemp(SHARED_PHOTO_BASE64_KEY);
|
||||
|
||||
this.imageFileName = this.$route.query["fileName"] as string;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user