Refactor: Dokumentenabfragefunktionen hinzufügen und Mock-Daten importieren

- _documents aus dem Mock-Modul importieren
 - DocQuery-Typ für optionale Abfrageparameter hinzufügen
 - Implementierung der Funktionen getDocuments, getDocumentById und getDocumentByName
 - Beibehaltung der ursprünglichen Doc-Typ-Definition für Konsistenz
This commit is contained in:
tekh 2025-07-09 13:36:54 +02:00
parent 0009ceae81
commit 49452998cb
2 changed files with 28 additions and 1 deletions

View File

@ -261,7 +261,7 @@ function base64ToUint8Array(base64: string): Uint8Array {
return bytes;
}
export const documents: Doc[] = [
export const _documents: Doc[] = [
{
id: 1,
name: "example1.pdf",

View File

@ -1,5 +1,32 @@
import { _documents } from "src/_mock"
export type Doc = {
id: number,
name: string,
data: Uint8Array
}
export type DocQuery = {
id?: number | undefined,
name?: string | undefined
}
export function getDocuments({ id, name }: DocQuery): Promise<Doc[]> {
let documents = _documents;
if (id)
documents = documents.filter(d => d.id = id)
if (name)
documents = documents.filter(d => d.name = name)
return Promise.resolve(documents);
}
export function getDocumentById(id: number): Promise<Doc[]> {
return getDocuments({ id: id });
}
export function getDocumentByName(name: string): Promise<Doc[]> {
return getDocuments({ name: name });
}