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
|
||||
|
||||
@@ -46,12 +46,12 @@
|
||||
<ul role="list" class="divide-y divide-gray-100">
|
||||
{#each caseList as item}
|
||||
<li>
|
||||
<a href="/list/{item.name}?token={item.token}" class="flex justify-between gap-x-6 py-5">
|
||||
<a href="/list/{item.token}?token={item.pw}" class="flex justify-between gap-x-6 py-5">
|
||||
<div class="flex gap-x-4">
|
||||
<!-- Ordner -->
|
||||
<Folder />
|
||||
<div class="min-w-0 flex-auto">
|
||||
<span class="text-sm font-semibold leading-6 text-gray-900">{item[1]}</span>
|
||||
<span class="text-sm font-semibold leading-6 text-gray-900">{item.name}</span>
|
||||
<!-- Delete button -->
|
||||
<button
|
||||
style="padding: 2px"
|
||||
|
||||
Reference in New Issue
Block a user