feat(reporting): bill of materials (#275)

* new reporting service

* API route

* code gen

* get tsv export from tools page

* fix naming
This commit is contained in:
Hayden 2023-02-13 10:00:29 -09:00 committed by GitHub
parent 2e96d8c4c2
commit 9361997a42
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 291 additions and 91 deletions

View file

@ -0,0 +1,27 @@
import { BaseAPI, route } from "../base";
export class ReportsAPI extends BaseAPI {
async billOfMaterials(): Promise<void> {
const { data: stream, error } = await this.http.get<ReadableStream>({ url: route("/reporting/bill-of-materials") });
if (error) {
return;
}
const reader = stream.getReader();
let data = "";
while (true) {
const { done, value } = await reader.read();
if (done) {
break;
}
data += new TextDecoder("utf-8").decode(value);
}
const blob = new Blob([data], { type: "text/tsv" });
const link = document.createElement("a");
link.href = window.URL.createObjectURL(blob);
link.download = "bill-of-materials.tsv";
link.click();
}
}

View file

@ -7,6 +7,7 @@ import { UserApi } from "./classes/users";
import { ActionsAPI } from "./classes/actions";
import { StatsAPI } from "./classes/stats";
import { AssetsApi } from "./classes/assets";
import { ReportsAPI } from "./classes/reports";
import { Requests } from "~~/lib/requests";
export class UserClient extends BaseAPI {
@ -18,6 +19,7 @@ export class UserClient extends BaseAPI {
actions: ActionsAPI;
stats: StatsAPI;
assets: AssetsApi;
reports: ReportsAPI;
constructor(requests: Requests, attachmentToken: string) {
super(requests, attachmentToken);
@ -30,6 +32,7 @@ export class UserClient extends BaseAPI {
this.actions = new ActionsAPI(requests);
this.stats = new StatsAPI(requests);
this.assets = new AssetsApi(requests);
this.reports = new ReportsAPI(requests);
Object.freeze(this);
}