fix(format) perbaikan formatting
parent
caa9ea14fc
commit
d5f0fe6517
|
@ -1,3 +1 @@
|
||||||
export const DatabaseListen = [
|
export const DatabaseListen = ['transaction'];
|
||||||
'transaction'
|
|
||||||
]
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ import { CqrsModule } from '@nestjs/cqrs';
|
||||||
imports: [
|
imports: [
|
||||||
ConfigModule.forRoot(),
|
ConfigModule.forRoot(),
|
||||||
// TypeOrmModule.forFeature([UserPrivilegeModel], CONNECTION_NAME.DEFAULT),
|
// TypeOrmModule.forFeature([UserPrivilegeModel], CONNECTION_NAME.DEFAULT),
|
||||||
CqrsModule,
|
CqrsModule,
|
||||||
],
|
],
|
||||||
controllers: [CouchDataController],
|
controllers: [CouchDataController],
|
||||||
providers: [CouchService],
|
providers: [CouchService],
|
||||||
|
|
|
@ -1,35 +1,31 @@
|
||||||
import { Injectable } from "@nestjs/common";
|
import { Injectable } from '@nestjs/common';
|
||||||
import { DatabaseListen } from "../../constants";
|
import { DatabaseListen } from '../../constants';
|
||||||
import { EventBus } from "@nestjs/cqrs";
|
import { EventBus } from '@nestjs/cqrs';
|
||||||
import { ChangeDocEvent } from "../../domain/events/change-doc.event";
|
import { ChangeDocEvent } from '../../domain/events/change-doc.event';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CouchService {
|
export class CouchService {
|
||||||
|
constructor(private eventBus: EventBus) {}
|
||||||
|
|
||||||
constructor(
|
async onModuleInit() {
|
||||||
private eventBus: EventBus,
|
const nano = require('nano')('http://root:password@172.10.10.2:5970');
|
||||||
) {}
|
for (const database of DatabaseListen) {
|
||||||
|
const db = nano.db.use(database);
|
||||||
|
db.changesReader.start({ includeDocs: true }).on('change', (change) => {
|
||||||
|
this.changeDoc(change, database);
|
||||||
|
});
|
||||||
|
|
||||||
async onModuleInit() {
|
console.log(`start listen database ${database}`);
|
||||||
const nano = require('nano')('http://root:password@172.10.10.2:5970');
|
|
||||||
for (const database of DatabaseListen) {
|
|
||||||
const db = nano.db.use(database)
|
|
||||||
db.changesReader.start({ includeDocs: true })
|
|
||||||
.on('change', (change) => {
|
|
||||||
this.changeDoc(change, database);
|
|
||||||
})
|
|
||||||
|
|
||||||
console.log(`start listen database ${database}`)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private changeDoc(data, database) {
|
private changeDoc(data, database) {
|
||||||
this.eventBus.publish(
|
this.eventBus.publish(
|
||||||
new ChangeDocEvent({
|
new ChangeDocEvent({
|
||||||
id: data.id,
|
id: data.id,
|
||||||
database: database,
|
database: database,
|
||||||
data: data.doc,
|
data: data.doc,
|
||||||
})
|
}),
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
export class ChangeDocEvent {
|
export class ChangeDocEvent {
|
||||||
constructor(public readonly data: IEventDoc) {}
|
constructor(public readonly data: IEventDoc) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IEventDoc {
|
export interface IEventDoc {
|
||||||
id: string,
|
id: string;
|
||||||
database: string,
|
database: string;
|
||||||
data: any,
|
data: any;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue