acknowledgement.service.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 settings1: LogSetting = {
  11. storage: '',
  12. setting: {
  13. appId: '',
  14. appName: '',
  15. logLocName: '',
  16. logLocId: '',
  17. appLogLocId: '',
  18. appLocName: '',
  19. appLogId: ''
  20. }
  21. }
  22. private settings2: LogSetting = {
  23. storage: '',
  24. setting: {
  25. appId: '',
  26. appName: '',
  27. logLocName: '',
  28. logLocId: '',
  29. appLogLocId: '',
  30. appLocName: '',
  31. appLogId: ''
  32. }
  33. }
  34. constructor(private logService1?: LoggingService, private logService2?: LoggingService) {
  35. this.logService1 = new LoggingService()
  36. this.logService2 = new LoggingService()
  37. }
  38. // set the data. I dont know what to set yet
  39. public async init(settings: AcknowledgementLogSetting) {
  40. let logSetting1: LogSetting = {
  41. ...settings,
  42. setting: {
  43. ...settings.setting,
  44. logLocName: "locationName1",
  45. appLocName: "appLocName1"
  46. }
  47. }
  48. let logSetting2: LogSetting = {
  49. ...settings,
  50. setting: {
  51. ...settings.setting,
  52. logLocName: "locationName2",
  53. appLocName: "appLocName2"
  54. }
  55. }
  56. // console.log(settings)
  57. this.settings1 = logSetting1
  58. this.logService1.init(logSetting1)
  59. this.settings2 = logSetting2
  60. this.logService2.init(logSetting2)
  61. }
  62. // suppose to call logging service to give an observable type report for every message streamed
  63. public subscribe(obs: Observable<any>): Observable<ResponseMessage> {
  64. this.logService1.subscribe(obs)
  65. let acknowledgementToken: Observable<ResponseMessage> = obs.pipe(
  66. map(
  67. incoming_msg => {
  68. let emulatedId = "GeneratedFromMessageSync"
  69. let emulatedRequest = this.messageUtil.getCommandMessage(emulatedId, Command.New, incoming_msg)
  70. let finalResponse = this.messageUtil.getResponseMessage(emulatedId, { "Acknowledgement": 1 }, emulatedRequest)
  71. return finalResponse
  72. }
  73. ))
  74. let acknowledgementTokenLogging: Observable<MessageLog> = obs.pipe(
  75. map(
  76. incoming_msg => {
  77. let finalResponse:MessageLog = {
  78. appLogLocId: this.settings2.setting.appLogId || "",
  79. appData: {
  80. msgId: new Uuid().generateId(),
  81. msgLogDateTime: new Date(),
  82. msgDateTime: new Date(),
  83. msgTag: ['Acknowledgement'],
  84. msgPayload: JSON.stringify(incoming_msg)
  85. }
  86. }
  87. return finalResponse
  88. }
  89. )
  90. )
  91. this.logService2.subscribe(acknowledgementTokenLogging)
  92. return acknowledgementToken
  93. }
  94. }