fix: try to reconcile types

pull/249/head
Sylvie 6 months ago
parent 778f25761d
commit 0abf3a2188
No known key found for this signature in database
GPG Key ID: 75AB0FE5B983A3AF

@ -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");

@ -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);
});
}
}

@ -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);
}

@ -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 = {

Loading…
Cancel
Save