Alexey Velikiy
6 years ago
9 changed files with 535 additions and 514 deletions
@ -1,46 +1,32 @@
|
||||
import { Collection, makeDBQ } from '../services/data_service'; |
||||
|
||||
|
||||
let db = makeDBQ(Collection.METRICS); |
||||
|
||||
|
||||
export type Datasource = { |
||||
method: string, |
||||
data: Object, |
||||
params: Object, |
||||
type: string, |
||||
url: string |
||||
} |
||||
|
||||
export type MetricId = string; |
||||
|
||||
export type Metric = { |
||||
id?: MetricId, |
||||
datasource: Datasource, |
||||
targets: string[] |
||||
} |
||||
|
||||
export function metricFromObj(obj: any): Metric { |
||||
export class Metric { |
||||
constructor(public datasource: string, public targets: any[]) { |
||||
if(datasource === undefined) { |
||||
throw new Error('datasource is undefined'); |
||||
} |
||||
if(targets === undefined) { |
||||
throw new Error('targets is undefined'); |
||||
} |
||||
if(targets.length === 0) { |
||||
throw new Error('targets is empty'); |
||||
} |
||||
} |
||||
|
||||
public toObject() { |
||||
return { |
||||
datasource: obj.datasource, |
||||
targets: obj.targets |
||||
datasource: this.datasource, |
||||
targets: this.targets |
||||
}; |
||||
} |
||||
|
||||
// export async function saveTargets(targets: string[]) {
|
||||
// let metrics = [];
|
||||
// for (let target of targets) {
|
||||
// metrics.push(create(target));
|
||||
// }
|
||||
// return metrics;
|
||||
// }
|
||||
|
||||
export async function create(metric: Metric): Promise<MetricId> { |
||||
return metric.id = await db.insert(metric); |
||||
} |
||||
|
||||
export async function findMetric(id: MetricId): Promise<Metric> { |
||||
return db.findOne(id); |
||||
} |
||||
|
||||
static fromObject(obj: any): Metric { |
||||
if(obj === undefined) { |
||||
throw new Error('obj is undefined'); |
||||
} |
||||
return new Metric( |
||||
obj.datasource, |
||||
obj.targets |
||||
); |
||||
} |
||||
} |
||||
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
class Task { |
||||
export class Task { |
||||
|
||||
} |
Loading…
Reference in new issue