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 |
|
||||||
} |
} |
||||||
|
|
||||||
export type MetricId = string; |
|
||||||
|
|
||||||
export type Metric = { |
|
||||||
id?: MetricId, |
|
||||||
datasource: Datasource, |
|
||||||
targets: string[] |
|
||||||
} |
} |
||||||
|
|
||||||
export function metricFromObj(obj: any): Metric { |
public toObject() { |
||||||
return { |
return { |
||||||
datasource: obj.datasource, |
datasource: this.datasource, |
||||||
targets: obj.targets |
targets: this.targets |
||||||
}; |
}; |
||||||
} |
} |
||||||
|
|
||||||
// export async function saveTargets(targets: string[]) {
|
static fromObject(obj: any): Metric { |
||||||
// let metrics = [];
|
if(obj === undefined) { |
||||||
// for (let target of targets) {
|
throw new Error('obj is undefined'); |
||||||
// metrics.push(create(target));
|
} |
||||||
// }
|
return new Metric( |
||||||
// return metrics;
|
obj.datasource, |
||||||
// }
|
obj.targets |
||||||
|
); |
||||||
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