acknowledgement.service.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { AnyObject } from "mongoose";
  2. import { map, Observable, of, tap } from "rxjs";
  3. import { Command, ResponseMessage, Uuid } from "../dependencies/fisappmessagejsutilty/interface/export"
  4. import { FisCreateMessageUtility } from "../dependencies/fisappmessagejsutilty/interface/export";
  5. import { LoggingService } from "../dependencies/fisloggingservice/services/logging-service";
  6. import { LogSetting, MessageLog } from "../dependencies/fisloggingservice/type/datatype";
  7. import { Acknowledgemeent, AcknowledgementLogSetting } from "../type/acknowledgement.interface";
  8. export class AcknowledgementService implements Acknowledgemeent {
  9. private messageUtil: FisCreateMessageUtility = new FisCreateMessageUtility("FisAppID/Name")
  10. private settings2: LogSetting = {
  11. storage: '',
  12. setting: {
  13. appId: '',
  14. appName: '',
  15. logLocName: '',
  16. logLocId: '',
  17. appLogLocId: '',
  18. appLocName: '',
  19. appLogId: ''
  20. }
  21. }
  22. constructor(private logService1?: LoggingService, private logService2?: LoggingService) {
  23. // this.logService1 = new LoggingService()
  24. this.logService2 = new LoggingService()
  25. }
  26. public async init(settings: AcknowledgementLogSetting) {
  27. // let logSetting1: LogSetting = {
  28. // ...settings,
  29. // setting: {
  30. // ...settings.setting,
  31. // logLocName: "locationName1",
  32. // appLocName: "appLocName1"
  33. // }
  34. // }
  35. let logSetting2: LogSetting = {
  36. ...settings,
  37. setting: {
  38. ...settings.setting,
  39. logLocName: "locationName2",
  40. appLocName: "appLocName2"
  41. }
  42. }
  43. // console.log(settings)
  44. // this.settings1 = logSetting1
  45. // this.logService1.init(logSetting1)
  46. this.settings2 = logSetting2
  47. this.logService2.init(logSetting2)
  48. }
  49. public subscribe(obs: Observable<any>): Observable<ResponseMessage> {
  50. let acknowledgementToken: Observable<ResponseMessage> = obs.pipe(
  51. map(
  52. incoming_msg => {
  53. let emulatedId = "GeneratedFromMessageSync"
  54. let emulatedRequest = this.messageUtil.getCommandMessage(emulatedId, Command.New, incoming_msg)
  55. let finalResponse = this.messageUtil.getResponseMessage(emulatedId, { "Acknowledgement": 1 }, emulatedRequest)
  56. return finalResponse
  57. }
  58. ))
  59. let acknowledgementTokenLogging: Observable<MessageLog> = obs.pipe(
  60. map(
  61. incoming_msg => {
  62. let finalResponse:MessageLog = {
  63. appLogLocId: this.settings2.setting.appLogId,
  64. appData: {
  65. msgId: new Uuid().generateId(),
  66. msgLogDateTime: new Date(),
  67. msgDateTime: new Date(),
  68. msgTag: ['Acknowledgement'],
  69. msgPayload: JSON.stringify(incoming_msg)
  70. }
  71. }
  72. return finalResponse
  73. }
  74. )
  75. )
  76. this.logService2.subscribe(acknowledgementTokenLogging)
  77. return acknowledgementToken
  78. }
  79. }