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:
parent
0009ceae81
commit
49452998cb
@ -261,7 +261,7 @@ function base64ToUint8Array(base64: string): Uint8Array {
|
|||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const documents: Doc[] = [
|
export const _documents: Doc[] = [
|
||||||
{
|
{
|
||||||
id: 1,
|
id: 1,
|
||||||
name: "example1.pdf",
|
name: "example1.pdf",
|
||||||
|
|||||||
@ -1,5 +1,32 @@
|
|||||||
|
import { _documents } from "src/_mock"
|
||||||
|
|
||||||
export type Doc = {
|
export type Doc = {
|
||||||
id: number,
|
id: number,
|
||||||
name: string,
|
name: string,
|
||||||
data: Uint8Array
|
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 });
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user