// NotificationService.js const EventProcessor = require("./EventProcessor"); const…
- User
// NotificationService.js const EventProcessor = require("./EventProcessor"); const OPVisitEventHandler = require("../events/OPVisitEventHandler"); const BillCreateEventHandler = require("../events/BillEventHandler"); const AdvanceCreateEventHandler = require("../events/AdvanceEventHandler"); const RefundCreateEventHandler = require("../events/RefundEventHandler"); const ReceiptCreateEventHandler = require("../events/ReceiptEventHandler"); const TemplateService = require("./TemplateService"); const CommunicationService = require("../core/CommunicatorService"); const FileService = require("./FileService"); class NotificationService { constructor(entityCode, enterpriseCode, logger) { this.entityCode = entityCode; this.enterpriseCode = enterpriseCode; this.logger = logger; this.templateService = new TemplateService( entityCode, enterpriseCode, logger, ); this.communicationService = new CommunicationService( entityCode, enterpriseCode, logger, ); this.fileService = new FileService(); this.eventProcessor = new EventProcessor(); // Register event handlers dynamically this.eventProcessor.registerHandler( "OP_VISIT_CREATED", new OPVisitEventHandler( this.templateService, this.communicationService, logger, ), ); this.eventProcessor.registerHandler( "BILL_CREATED", new BillCreateEventHandler( this.templateService, this.communicationService, this.fileService, logger, ), ); this.eventProcessor.registerHandler( "BILL_MODIFIED", new BillCreateEventHandler( this.templateService, this.communicationService, this.fileService, logger, ), ); this.eventProcessor.registerHandler( "ADVANCE_CREATED", new AdvanceCreateEventHandler( this.templateService, this.communicationService, this.fileService, logger, ), ); this.eventProcessor.registerHandler( "REFUND_CREATED", new RefundCreateEventHandler( this.templateService, this.communicationService, this.fileService, logger, ), ); this.eventProcessor.registerHandler( "RECEIPT_CREATED", new ReceiptCreateEventHandler( this.templateService, this.communicationService, this.fileService, logger, ), ); } async processNotification(notificationData) { try { const { type } = notificationData; try { const response = await this.eventProcessor.processEvent( type, notificationData, this.logger, ); // Log response or any other relevant information using the provided logger this.logger.info(
Notification processed successfully. Response: ${response}, ); // Return response return "Notification processed successfully"; } catch (error) { this.logger.error(Notification processing failed. Response: ${error}); // Return response return error?.message; } } catch (error) { // Log the error using the provided logger this.logger.error(Error processing notification: ${error}); throw new Error(error); } } } module.exports = NotificationService;THis is increasing day by day and difficult to scale how to solve this ?
- Assistant