From 0abf3a218872e2edd96f109f54c7a26d7c155e57 Mon Sep 17 00:00:00 2001 From: Sylvie Date: Sun, 3 Dec 2023 17:21:47 -0700 Subject: [PATCH] fix: try to reconcile types --- backend/sql/database.ts | 4 ++-- backend/sql/json.ts | 4 ++-- backend/sql/mysql.ts | 7 +++---- backend/sql/postgres.ts | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/backend/sql/database.ts b/backend/sql/database.ts index 978b404..f09edbb 100644 --- a/backend/sql/database.ts +++ b/backend/sql/database.ts @@ -36,7 +36,7 @@ export interface Database { /** * get all values from the database */ - getAll(table: DatabaseTable): Promise<{ [index: string]: DatabaseValue }>; + getAll(table: DatabaseTable): Promise<{ [key: string]: DatabaseValue | undefined }[]>; } export class DBManager { @@ -98,7 +98,7 @@ export class DBManager { /** * get all values from the database */ - public static getAll(table: DatabaseTable): Promise<{ [index: string]: DatabaseValue }> { + public static getAll(table: DatabaseTable): Promise<{ [key: string]: DatabaseValue | undefined }[]> { if (this._db && this._dbReady) { return this._db.getAll(table); } else throw new Error("No database active"); diff --git a/backend/sql/json.ts b/backend/sql/json.ts index 9a2233f..f7379b2 100644 --- a/backend/sql/json.ts +++ b/backend/sql/json.ts @@ -143,10 +143,10 @@ export class JSONDatabase implements Database { }); } - public getAll(table: DatabaseTable): Promise<{ [index: string]: DatabaseValue }> { + public getAll(table: DatabaseTable): Promise<{ Data: DatabaseValue | undefined }[]> { return new Promise(async (resolve, reject) => { const data = (await fs.readJson(PATHMAP[table]))[SECTORMAP[table]]; - (!data) ? resolve({}) : resolve(data); + (!data) ? resolve(data) : resolve(data); }); } } \ No newline at end of file diff --git a/backend/sql/mysql.ts b/backend/sql/mysql.ts index 69a1305..7072b86 100644 --- a/backend/sql/mysql.ts +++ b/backend/sql/mysql.ts @@ -162,19 +162,18 @@ VALUES ('${key}', '${JSON.stringify(data)}'); } // todo: unknown if this works - public getAll(table: DatabaseTable): Promise<{ [index: string]: DatabaseValue }> { + public getAll(table: DatabaseTable): Promise<{ Data: DatabaseValue | undefined }[]> { return new Promise(async (resolve, reject) => { try { // Run query // ! this may not work as expected const [rowz, _fields] = await this._pool.query(`SELECT Data FROM ${table}`); // Interpret results this is pain - const rows = (rowz as unknown as { [key: string]: string }[]); + const rows = (rowz as unknown as { Data: UploadToken | AssFile | AssUser | undefined }[]); - // console.log(rows); // aaaaaaaaaaaa - resolve({}); + resolve(rows); } catch (err) { reject(err); } diff --git a/backend/sql/postgres.ts b/backend/sql/postgres.ts index 52e7fdc..1e38177 100644 --- a/backend/sql/postgres.ts +++ b/backend/sql/postgres.ts @@ -180,7 +180,7 @@ export class PostgreSQLDatabase implements Database { }); } - public getAll(table: DatabaseTable): Promise<{ [index: string]: DatabaseValue; }> { + public getAll(table: DatabaseTable): Promise<{ Data: DatabaseValue | undefined }[]> { return new Promise(async (resolve, reject) => { try { const queries = {