feat:
parent
a14119719c
commit
bca3682826
|
@ -3,7 +3,7 @@ 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';
|
||||||
import { ConfigService } from '@nestjs/config';
|
import { ConfigService } from '@nestjs/config';
|
||||||
|
import { apm } from 'src/core/apm';
|
||||||
import * as Nano from 'nano';
|
import * as Nano from 'nano';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
@ -49,7 +49,10 @@ export class CouchService {
|
||||||
const nano = this.nanoInstance;
|
const nano = this.nanoInstance;
|
||||||
const db = nano.use(database);
|
const db = nano.use(database);
|
||||||
return await db.insert(data);
|
return await db.insert(data);
|
||||||
} catch (error) {}
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
apm.captureError(error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async deleteDoc(data, database) {
|
public async deleteDoc(data, database) {
|
||||||
|
@ -58,7 +61,10 @@ export class CouchService {
|
||||||
const db = nano.use(database);
|
const db = nano.use(database);
|
||||||
const result = await db.get(data.id);
|
const result = await db.get(data.id);
|
||||||
await db.destroy(data.id, result._rev);
|
await db.destroy(data.id, result._rev);
|
||||||
} catch (error) {}
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
apm.captureError(error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async updateDoc(data, database) {
|
public async updateDoc(data, database) {
|
||||||
|
@ -70,7 +76,10 @@ export class CouchService {
|
||||||
...data,
|
...data,
|
||||||
_rev: result._rev,
|
_rev: result._rev,
|
||||||
});
|
});
|
||||||
} catch (error) {}
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
apm.captureError(error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getDoc(id: string, database: string) {
|
public async getDoc(id: string, database: string) {
|
||||||
|
@ -80,6 +89,8 @@ export class CouchService {
|
||||||
const result = await db.get(id);
|
const result = await db.get(id);
|
||||||
return result;
|
return result;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
apm.captureError(error);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import { TransactionChangeStatusEvent } from '../../entities/event/transaction-c
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||||
import { generateInvoiceCodeHelper } from '../managers/helpers/generate-invoice-code.helper';
|
import { generateInvoiceCodeHelper } from '../managers/helpers/generate-invoice-code.helper';
|
||||||
|
import { apm } from 'src/core/apm';
|
||||||
|
|
||||||
@EventsHandler(MidtransCallbackEvent)
|
@EventsHandler(MidtransCallbackEvent)
|
||||||
export class MidtransCallbackHandler
|
export class MidtransCallbackHandler
|
||||||
|
@ -22,6 +23,11 @@ export class MidtransCallbackHandler
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async handle(event: MidtransCallbackEvent) {
|
async handle(event: MidtransCallbackEvent) {
|
||||||
|
const apmTransactions = apm.startTransaction(
|
||||||
|
`callback-midtrans`,
|
||||||
|
'handler',
|
||||||
|
);
|
||||||
|
|
||||||
const data_id = event.data.id;
|
const data_id = event.data.id;
|
||||||
const data = event.data.data;
|
const data = event.data.data;
|
||||||
let old_data = undefined;
|
let old_data = undefined;
|
||||||
|
@ -33,6 +39,8 @@ export class MidtransCallbackHandler
|
||||||
});
|
});
|
||||||
old_data = _.cloneDeep(transaction);
|
old_data = _.cloneDeep(transaction);
|
||||||
|
|
||||||
|
apmTransactions.setLabel('status', data.transaction_status);
|
||||||
|
|
||||||
if (['capture', 'settlement'].includes(data.transaction_status)) {
|
if (['capture', 'settlement'].includes(data.transaction_status)) {
|
||||||
Object.assign(transaction, {
|
Object.assign(transaction, {
|
||||||
status: STATUS.SETTLED,
|
status: STATUS.SETTLED,
|
||||||
|
@ -69,5 +77,7 @@ export class MidtransCallbackHandler
|
||||||
op: OPERATION.UPDATE,
|
op: OPERATION.UPDATE,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
apmTransactions.end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue