2023-07-04 21:21:34 +00:00
|
|
|
import {InstallPrefs} from "app/common/Install";
|
|
|
|
import {ApiError} from "app/common/ApiError";
|
|
|
|
import {InstallProperties, installPropertyKeys} from "app/common/InstallAPI";
|
|
|
|
import {nativeValues} from "app/gen-server/lib/values";
|
2022-05-11 19:05:35 +00:00
|
|
|
import {BaseEntity, Column, Entity, PrimaryColumn} from "typeorm";
|
|
|
|
|
|
|
|
@Entity({name: 'activations'})
|
|
|
|
export class Activation extends BaseEntity {
|
|
|
|
|
|
|
|
@PrimaryColumn()
|
|
|
|
public id: string;
|
|
|
|
|
|
|
|
@Column({name: 'key', type: 'text', nullable: true})
|
|
|
|
public key: string|null;
|
|
|
|
|
2023-07-04 21:21:34 +00:00
|
|
|
@Column({type: nativeValues.jsonEntityType, nullable: true})
|
|
|
|
public prefs: InstallPrefs|null;
|
|
|
|
|
2022-05-11 19:05:35 +00:00
|
|
|
@Column({name: 'created_at', default: () => "CURRENT_TIMESTAMP"})
|
|
|
|
public createdAt: Date;
|
|
|
|
|
|
|
|
@Column({name: 'updated_at', default: () => "CURRENT_TIMESTAMP"})
|
|
|
|
public updatedAt: Date;
|
2023-07-04 21:21:34 +00:00
|
|
|
|
|
|
|
public checkProperties(props: any): props is Partial<InstallProperties> {
|
|
|
|
for (const key of Object.keys(props)) {
|
|
|
|
if (!installPropertyKeys.includes(key)) {
|
|
|
|
throw new ApiError(`Unrecognized property ${key}`, 400);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public updateFromProperties(props: Partial<InstallProperties>) {
|
|
|
|
if (props.prefs === undefined) { return; }
|
|
|
|
|
|
|
|
if (props.prefs === null) {
|
|
|
|
this.prefs = null;
|
|
|
|
} else {
|
|
|
|
this.prefs = this.prefs || {};
|
|
|
|
if (props.prefs.telemetry !== undefined) {
|
|
|
|
this.prefs.telemetry = this.prefs.telemetry || {};
|
|
|
|
if (props.prefs.telemetry.telemetryLevel !== undefined) {
|
|
|
|
this.prefs.telemetry.telemetryLevel = props.prefs.telemetry.telemetryLevel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const key of Object.keys(this.prefs) as Array<keyof InstallPrefs>) {
|
|
|
|
if (this.prefs[key] === null) {
|
|
|
|
delete this.prefs[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Object.keys(this.prefs).length === 0) {
|
|
|
|
this.prefs = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-05-11 19:05:35 +00:00
|
|
|
}
|