refactor getVorgaenge to return vorgaenge as objects
This commit is contained in:
@@ -2,6 +2,9 @@ import { fail } from '@sveltejs/kit';
|
||||
import { BUCKET, client, CONFIGFILENAME, TOKENFILENAME } from '$lib/minio';
|
||||
import { checkIfExactDirectoryExists, getContentOfTextObject } from './s3ClientService';
|
||||
|
||||
import Database from 'better-sqlite3';
|
||||
const db = new Database('./src/lib/data/tatort.db');
|
||||
|
||||
/**
|
||||
* Get Vorgang and corresponend list of tatorte
|
||||
* @param caseId
|
||||
@@ -17,21 +20,20 @@ export const getVorgangByCaseId = async (caseId: string) => {
|
||||
const splittedNameParts = chunk.name.split('/');
|
||||
const prefix = splittedNameParts[0];
|
||||
const name = splittedNameParts[1];
|
||||
|
||||
|
||||
if (name === CONFIGFILENAME || name === TOKENFILENAME) continue;
|
||||
list.push({ ...chunk, name: name, prefix: prefix, show_button: true });
|
||||
}
|
||||
return list;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Fetches list of vorgänge from s3 bucket
|
||||
* @returns list of available cases
|
||||
*/
|
||||
export const getListOfVorgänge = async () => {
|
||||
const stream = client.listObjectsV2(BUCKET, '', false, '');
|
||||
|
||||
|
||||
const list = [];
|
||||
for await (const chunk of stream) {
|
||||
const objPath = `${chunk.prefix}${TOKENFILENAME}`;
|
||||
@@ -44,6 +46,23 @@ export const getListOfVorgänge = async () => {
|
||||
return list;
|
||||
};
|
||||
|
||||
/**
|
||||
* Fetches list of vorgänge from database
|
||||
* @returns list with of available cases
|
||||
*/
|
||||
export const getVorgaenge = function () {
|
||||
let getVorgaenge_stmt = `SELECT token, name, pw from cases`;
|
||||
const stmt = db.prepare(getVorgaenge_stmt);
|
||||
const res = stmt.all();
|
||||
const vorgaenge_list = [];
|
||||
for (const r of res) {
|
||||
const vorg = { token: r.token, name: r.name, pw: r.pw };
|
||||
vorgaenge_list.push(vorg);
|
||||
}
|
||||
|
||||
return vorgaenge_list;
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks if Vorgang exists
|
||||
* @param request
|
||||
|
||||
Reference in New Issue
Block a user