Files

114 lines
3.3 KiB
TypeScript
Executable File

export namespace models {
export class Note {
id: number;
parentId: number;
title: string;
content: string;
sortOrder: number;
isFolder: boolean;
tag: string;
// Go type: time
createdAt: any;
// Go type: time
updatedAt: any;
// Go type: time
deletedAt?: any;
children?: Note[];
static createFrom(source: any = {}) {
return new Note(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.id = source["id"];
this.parentId = source["parentId"];
this.title = source["title"];
this.content = source["content"];
this.sortOrder = source["sortOrder"];
this.isFolder = source["isFolder"];
this.tag = source["tag"];
this.createdAt = this.convertValues(source["createdAt"], null);
this.updatedAt = this.convertValues(source["updatedAt"], null);
this.deletedAt = this.convertValues(source["deletedAt"], null);
this.children = this.convertValues(source["children"], Note);
}
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;
}
}
export class NoteTree {
id: number;
parentId: number;
title: string;
content: string;
sortOrder: number;
isFolder: boolean;
tag: string;
// Go type: time
createdAt: any;
// Go type: time
updatedAt: any;
// Go type: time
deletedAt?: any;
children?: Note[];
children: NoteTree[];
static createFrom(source: any = {}) {
return new NoteTree(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.id = source["id"];
this.parentId = source["parentId"];
this.title = source["title"];
this.content = source["content"];
this.sortOrder = source["sortOrder"];
this.isFolder = source["isFolder"];
this.tag = source["tag"];
this.createdAt = this.convertValues(source["createdAt"], null);
this.updatedAt = this.convertValues(source["updatedAt"], null);
this.deletedAt = this.convertValues(source["deletedAt"], null);
this.children = this.convertValues(source["children"], Note);
this.children = this.convertValues(source["children"], NoteTree);
}
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;
}
}
}