mirror of
https://github.com/hay-kot/homebox.git
synced 2025-05-24 14:12:32 +00:00
feat: new homepage statistic API's (#167)
* add date format and orDefault helpers * introduce new statistics calculations queries * rework statistics endpoints * code generation * fix styles on photo card * label and location aggregation endpoints * code-gen * cleanup parser and defaults * remove debug point * setup E2E Testing * linters * formatting * fmt plus name support on time series data * code gen
This commit is contained in:
parent
de419dc37d
commit
d6da63187b
19 changed files with 925 additions and 149 deletions
|
@ -1,5 +1,5 @@
|
|||
import { BaseAPI, route } from "../base";
|
||||
import { Group, GroupInvitation, GroupInvitationCreate, GroupStatistics, GroupUpdate } from "../types/data-contracts";
|
||||
import { Group, GroupInvitation, GroupInvitationCreate, GroupUpdate } from "../types/data-contracts";
|
||||
|
||||
export class GroupApi extends BaseAPI {
|
||||
createInvitation(data: GroupInvitationCreate) {
|
||||
|
@ -21,10 +21,4 @@ export class GroupApi extends BaseAPI {
|
|||
url: route("/groups"),
|
||||
});
|
||||
}
|
||||
|
||||
statistics() {
|
||||
return this.http.get<GroupStatistics>({
|
||||
url: route("/groups/statistics"),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ export class ItemsApi extends BaseAPI {
|
|||
return payload;
|
||||
}
|
||||
|
||||
import(file: File) {
|
||||
import(file: File | Blob) {
|
||||
const formData = new FormData();
|
||||
formData.append("csv", file);
|
||||
|
||||
|
|
42
frontend/lib/api/classes/stats.ts
Normal file
42
frontend/lib/api/classes/stats.ts
Normal file
|
@ -0,0 +1,42 @@
|
|||
import { BaseAPI, route } from "../base";
|
||||
import { GroupStatistics, TotalsByOrganizer, ValueOverTime } from "../types/data-contracts";
|
||||
|
||||
function YYYY_DD_MM(date?: Date): string {
|
||||
if (!date) {
|
||||
return "";
|
||||
}
|
||||
// with leading zeros
|
||||
const year = date.getFullYear();
|
||||
const month = (date.getMonth() + 1).toString().padStart(2, "0");
|
||||
const day = date.getDate().toString().padStart(2, "0");
|
||||
return `${year}-${month}-${day}`;
|
||||
}
|
||||
export class StatsAPI extends BaseAPI {
|
||||
totalPriceOverTime(start?: Date, end?: Date) {
|
||||
return this.http.get<ValueOverTime>({
|
||||
url: route("/groups/statistics/purchase-price", { start: YYYY_DD_MM(start), end: YYYY_DD_MM(end) }),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns ths general statistics for the group. This mostly just
|
||||
* includes the totals for various group properties.
|
||||
*/
|
||||
group() {
|
||||
return this.http.get<GroupStatistics>({
|
||||
url: route("/groups/statistics"),
|
||||
});
|
||||
}
|
||||
|
||||
labels() {
|
||||
return this.http.get<TotalsByOrganizer[]>({
|
||||
url: route("/groups/statistics/labels"),
|
||||
});
|
||||
}
|
||||
|
||||
locations() {
|
||||
return this.http.get<TotalsByOrganizer[]>({
|
||||
url: route("/groups/statistics/locations"),
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue