feat: improve CouchService change handling and enhance async processing

pull/176/head 1.7.1-alpha.3
shancheas 2025-07-10 18:36:09 +07:00
parent a86cd8880f
commit 41f691f02e
2 changed files with 13 additions and 11 deletions

View File

@ -23,12 +23,14 @@ export class CouchService {
const nano = this.nanoInstance;
for (const database of DatabaseListen) {
const db = nano.db.use(database);
db.changesReader.start({ includeDocs: true }).on('change', (change) => {
db.changesReader
.start({ includeDocs: true })
.on('change', async (change) => {
Logger.verbose(
`Receive Data from ${database}: ${change?.id}`,
'CouchService',
);
this.changeDoc(change, database);
await this.changeDoc(change, database);
});
// transaction
@ -36,8 +38,8 @@ export class CouchService {
}
}
private changeDoc(data, database) {
this.eventBus.publish(
private async changeDoc(data, database) {
await this.eventBus.publish(
new ChangeDocEvent({
id: data.id,
database: database,
@ -111,8 +113,8 @@ export class CouchService {
const selector = {
created_at: {
$gte: todayTimestamp,
status: 'settled',
},
status: 'settled',
};
const result = await db.find({

View File

@ -42,10 +42,10 @@ export class PosTransactionHandler implements IEventHandler<ChangeDocEvent> {
try {
const database = event.data.database;
const data = { ...event.data.data };
Logger.log(`receipt data with code ${data?.code}`);
// jika bukan database transaksi, return langsung
if (database != 'transaction') return;
Logger.log(`receipt data with code ${data?.code}`);
const sales_formula = await this.formulaService.getOneByOptions({
where: {