123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- import { AnyObject } from "mongoose";
- import { map, Observable, of, tap } from "rxjs";
- import { 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 settings1: LogSetting = {
- // storage: '',
- // setting: {
- // appId: '',
- // appName: '',
- // logLocName: '',
- // logLocId: '',
- // appLogLocId: '',
- // appLocName: '',
- // appLogId: ''
- // }
- // }
- private settings2: LogSetting = {
- storage: '',
- setting: {
- appId: '',
- appName: '',
- logLocName: '',
- logLocId: '',
- appLogLocId: '',
- appLocName: '',
- appLogId: ''
- }
- }
- constructor(private logService1?: LoggingService, private logService2?: LoggingService) {
- // this.logService1 = new LoggingService()
- this.logService2 = new LoggingService()
- }
- // set the data. I dont know what to set yet
- public async init(settings: AcknowledgementLogSetting) {
- // let logSetting1: LogSetting = {
- // ...settings,
- // setting: {
- // ...settings.setting,
- // logLocName: "locationName1",
- // appLocName: "appLocName1"
- // }
- // }
- let logSetting2: LogSetting = {
- ...settings,
- setting: {
- ...settings.setting,
- logLocName: "locationName2",
- appLocName: "appLocName2"
- }
- }
- // console.log(settings)
- // this.settings1 = logSetting1
- // this.logService1.init(logSetting1)
- this.settings2 = logSetting2
- this.logService2.init(logSetting2)
- }
- // suppose to call logging service to give an observable type report for every message streamed
- public subscribe(obs: Observable<any>): Observable<ResponseMessage> {
- let acknowledgementToken: Observable<ResponseMessage> = 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<MessageLog> = obs.pipe(
- map(
- incoming_msg => {
- let finalResponse:MessageLog = {
- appLogLocId: this.settings2.setting.appLogId || "",
- appData: {
- msgId: new Uuid().generateId(),
- msgLogDateTime: new Date(),
- msgDateTime: new Date(),
- msgTag: ['Acknowledgement'],
- msgPayload: JSON.stringify(incoming_msg)
- }
- }
- return finalResponse
- }
- )
- )
- this.logService2.subscribe(acknowledgementTokenLogging)
- return acknowledgementToken
- }
- }
|