import { map, Observable, of, tap } from "rxjs"; import { BaseMessage, Command, ResponseMessage, Uuid } from "../dependencies/fisappmessagejsutilty/interface/export" import { LoggingService } from "../dependencies/fisloggingservice/services/logging-service"; import { LogSetting, MessageLog } from "../dependencies/fisloggingservice/type/datatype"; import { IncomingMessageServiceInterface } from "../type/datatype"; import { AcknowledgementService } from "./acknowledgement.service"; export class IncomingMessageService implements IncomingMessageServiceInterface { constructor(private logService?: LoggingService, private acknowledgeService?: AcknowledgementService) { this.logService = new LoggingService() } private settings: LogSetting & { incomingObservable: Observable; } = { storage: '', setting: { appId: '', appName: '', logLocName: '', logLocId: '', appLogLocId: '', appLocName: '', appLogId: '' }, incomingObservable: null } public init(settings: LogSetting & { incomingObservable: Observable; }): void { let newSetting: any = settings newSetting.setting = { ...this.settings.setting, ...settings.setting, customSetting:{ ...this.settings.customSetting, ...settings.customSetting, } } this.settings = newSetting // Transform incoming observables into Observable to be logged let transformedOBS: Observable = settings.incomingObservable.pipe( map(message => { let finalResponse: MessageLog = { appLogLocId: new Uuid().generateId(), appData: { msgId: message.header.messageID || new Uuid().generateId(), msgLogDateTime: new Date(), msgDateTime: new Date(), msgTag: ['Incoming'], msgPayload: JSON.stringify(message) } } return finalResponse } ) ) /* Trying new promise chaining structure */ this.logService.init(this.settings).then(() => { this.logService.subscribe(transformedOBS) }).catch((e) => console.error(e)) } }