import { AnyObject } from "mongoose"; import { map, Observable, of, tap } from "rxjs"; import { BaseMessage, Command, ResponseMessage, Uuid } from "../dependencies/fisappmessagejsutilty/interface/export" import { FisCreateMessageUtility } from "../dependencies/fisappmessagejsutilty/interface/export"; import { LoggingService } from "../dependencies/fisloggingservice/services/logging-service"; import { LogSetting, MessageLog } from "../dependencies/fisloggingservice/type/datatype"; import { Acknowledgemeent, AcknowledgementLogSetting } from "../type/acknowledgement.interface"; export class AcknowledgementService implements Acknowledgemeent { private messageUtil: FisCreateMessageUtility = new FisCreateMessageUtility("FisAppID/Name") private settings: LogSetting = { storage: '', setting: { appId: '', appName: '', logLocName: '', logLocId: '', appLogLocId: '', appLocName: '', appLogId: '' } } constructor(private logService1?: LoggingService, private logService?: LoggingService) { // this.logService1 = new LoggingService() this.logService = new LoggingService() } public async init(settings: AcknowledgementLogSetting) { let logSetting: LogSetting = { ...settings, setting: { ...settings.setting, logLocName: "locationName2", appLocName: "appLocName2" } } this.settings = logSetting this.logService.init(logSetting) } public subscribe(obs: Observable): Observable { let acknowledgementToken: Observable = obs.pipe( map( incoming_msg => { let emulatedId = "GeneratedFromMessageSync" let emulatedRequest = this.messageUtil.getCommandMessage(emulatedId, Command.New, incoming_msg) let finalResponse = this.messageUtil.getResponseMessage(emulatedId, { "Acknowledgement": 1 }, emulatedRequest) return finalResponse } )) let acknowledgementTokenLogging: Observable = obs.pipe( map( incoming_msg => { let finalResponse:MessageLog = { appLogLocId: new Uuid().generateId(), appData: { msgId: incoming_msg.header.messageID || new Uuid().generateId(), msgLogDateTime: new Date(), msgDateTime: new Date(), msgTag: ['Acknowledgement'], msgPayload: JSON.stringify(incoming_msg) } } return finalResponse } ) ) this.logService.subscribe(acknowledgementTokenLogging) return acknowledgementToken } }