-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample-heir-class.ts
More file actions
30 lines (26 loc) · 957 Bytes
/
example-heir-class.ts
File metadata and controls
30 lines (26 loc) · 957 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { randomUUID } from "crypto";
import { StaticImplements } from "protoobject";
import { BaseRecord, BaseRecordStaticMethods } from "./example-base-class";
@StaticImplements<BaseRecordStaticMethods<ApplicationRecord>>()
export class ApplicationRecord extends BaseRecord<ApplicationRecord> {
constructor(data?: Partial<ApplicationRecord>) {
super(data);
if (!(this as any).api_key) (this as any).api_key = randomUUID();
}
public static override table: string = `applications`;
public static fromJSON<T>(data: { [key: string]: unknown }) {
return new ApplicationRecord({
...super.fromJSON(data),
app_params:
typeof data?.app_params === "string"
? JSON.parse(data.app_params)
: undefined,
}) as T;
}
public toJSON(): { [key: string]: any } {
return {
...super.toJSON.call(this),
app_params: this.app_params ? JSON.stringify(this.app_params) : undefined,
};
}
}