Files
calorie-counter/frontend/wailsjs/go/models.ts
2024-08-09 18:15:08 +02:00

64 lines
1.6 KiB
TypeScript

export namespace main {
export class Food {
rowid: number;
date: string;
food: string;
description: string;
amount: number;
per100: number;
energy: number;
static createFrom(source: any = {}) {
return new Food(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.rowid = source["rowid"];
this.date = source["date"];
this.food = source["food"];
this.description = source["description"];
this.amount = source["amount"];
this.per100 = source["per100"];
this.energy = source["energy"];
}
}
export class WailsFood {
data: Food[];
success: boolean;
error?: string;
static createFrom(source: any = {}) {
return new WailsFood(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.data = this.convertValues(source["data"], Food);
this.success = source["success"];
this.error = source["error"];
}
convertValues(a: any, classs: any, asMap: boolean = false): any {
if (!a) {
return a;
}
if (a.slice && a.map) {
return (a as any[]).map(elem => this.convertValues(elem, classs));
} else if ("object" === typeof a) {
if (asMap) {
for (const key of Object.keys(a)) {
a[key] = new classs(a[key]);
}
return a;
}
return new classs(a);
}
return a;
}
}
}