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'; |
export class Metric { |
||||||
|
constructor(public datasource: string, public targets: any[]) { |
||||||
|
if(datasource === undefined) { |
||||||
let db = makeDBQ(Collection.METRICS); |
throw new Error('datasource is undefined'); |
||||||
|
} |
||||||
|
if(targets === undefined) { |
||||||
export type Datasource = { |
throw new Error('targets is undefined'); |
||||||
method: string, |
} |
||||||
data: Object, |
if(targets.length === 0) { |
||||||
params: Object, |
throw new Error('targets is empty'); |
||||||
type: string, |
} |
||||||
url: string |
} |
||||||
} |
|
||||||
|
public toObject() { |
||||||
export type MetricId = string; |
return { |
||||||
|
datasource: this.datasource, |
||||||
export type Metric = { |
targets: this.targets |
||||||
id?: MetricId, |
}; |
||||||
datasource: Datasource, |
} |
||||||
targets: string[] |
|
||||||
} |
static fromObject(obj: any): Metric { |
||||||
|
if(obj === undefined) { |
||||||
export function metricFromObj(obj: any): Metric { |
throw new Error('obj is undefined'); |
||||||
return { |
} |
||||||
datasource: obj.datasource, |
return new Metric( |
||||||
targets: obj.targets |
obj.datasource, |
||||||
}; |
obj.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); |
|
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
|
@ -1,3 +1,3 @@ |
|||||||
class Task { |
export class Task { |
||||||
|
|
||||||
} |
} |
Loading…
Reference in new issue