Добавил datasource для daily-eccm-reports-v2
This commit is contained in:
parent
8cae9076bd
commit
40313185a5
2 changed files with 51 additions and 0 deletions
32
src/couchdb-datasources/daily-eccm-reports-v2.datasource.ts
Normal file
32
src/couchdb-datasources/daily-eccm-reports-v2.datasource.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
import { Injectable, Logger } from '@nestjs/common';
|
||||||
|
import { CouchDb } from '@app/event-emitter/couchdb-datasources/couchdb';
|
||||||
|
import nano from 'nano';
|
||||||
|
import {
|
||||||
|
DailyEccmV2ReportService,
|
||||||
|
Report,
|
||||||
|
} from 'src/reports/daily-eccm-v2.report.service';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class DailyEccmReportsV2Datasource {
|
||||||
|
private static logger = new Logger(DailyEccmReportsV2Datasource.name);
|
||||||
|
private static db = null;
|
||||||
|
private static initilized = false;
|
||||||
|
|
||||||
|
static async getDatasource(): Promise<nano.DocumentScope<Report>> {
|
||||||
|
if (DailyEccmReportsV2Datasource.initilized) {
|
||||||
|
return DailyEccmReportsV2Datasource.db;
|
||||||
|
}
|
||||||
|
DailyEccmReportsV2Datasource.initilized = true;
|
||||||
|
const n = CouchDb.getCouchDb();
|
||||||
|
const dbName = 'eccm_daily_reports_v2';
|
||||||
|
const dbs = await n.db.list();
|
||||||
|
if (!dbs.includes(dbName)) {
|
||||||
|
await n.db.create(dbName);
|
||||||
|
}
|
||||||
|
DailyEccmReportsV2Datasource.db = await n.db.use(dbName);
|
||||||
|
DailyEccmReportsV2Datasource.logger.log(
|
||||||
|
`Connected to daily reports db - ${dbName}`,
|
||||||
|
);
|
||||||
|
return DailyEccmReportsV2Datasource.db;
|
||||||
|
}
|
||||||
|
}
|
||||||
19
src/reports/daily-eccm-v2.report.service.ts
Normal file
19
src/reports/daily-eccm-v2.report.service.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
|
export type Params = any; // TODO
|
||||||
|
|
||||||
|
export type Report = {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
datetime: number;
|
||||||
|
datetimeFormatted: string;
|
||||||
|
params: Params; // query?, schedule?, etc TODO
|
||||||
|
data: any;
|
||||||
|
};
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class DailyEccmV2ReportService {
|
||||||
|
constructor(params: Params) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue