You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
946 B
44 lines
946 B
6 years ago
|
import { AnalyticUnitId } from "./analytic_unit_model";
|
||
|
|
||
|
|
||
6 years ago
|
export type AnalyticsTaskId = string;
|
||
|
export enum AnalyticsTaskType {
|
||
|
LEARN = 'LEARN',
|
||
|
PREDICT = 'PREDICT'
|
||
|
};
|
||
6 years ago
|
|
||
6 years ago
|
export class AnalyticsTask {
|
||
6 years ago
|
constructor(
|
||
|
public analyticUnitId: AnalyticUnitId,
|
||
6 years ago
|
public type: AnalyticsTaskType,
|
||
|
public payload?: any,
|
||
|
public id?: AnalyticsTaskId
|
||
6 years ago
|
) {
|
||
|
if(analyticUnitId === undefined) {
|
||
|
throw new Error('analyticUnitId is undefined');
|
||
|
}
|
||
6 years ago
|
if(type === undefined || type === null) {
|
||
|
throw new Error('type is undefined or null');
|
||
|
}
|
||
6 years ago
|
}
|
||
|
|
||
|
public toObject() {
|
||
|
return {
|
||
|
_id: this.id,
|
||
6 years ago
|
analyticUnitId: this.analyticUnitId,
|
||
|
type: this.type
|
||
6 years ago
|
};
|
||
|
}
|
||
|
|
||
6 years ago
|
static fromObject(obj: any): AnalyticsTask {
|
||
6 years ago
|
if(obj === undefined) {
|
||
|
throw new Error('obj is undefined');
|
||
|
}
|
||
6 years ago
|
return new AnalyticsTask(
|
||
6 years ago
|
obj.analyticUnitId,
|
||
6 years ago
|
obj.type as AnalyticsTaskType,
|
||
6 years ago
|
obj._id,
|
||
|
);
|
||
|
}
|
||
6 years ago
|
}
|