acknowledgemeent.service.ts 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { AnyObject } from "mongoose";
  2. import { map, Observable, of, tap } from "rxjs";
  3. import { Command, ResponseMessage } 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 } 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. this.logService2.subscribe(acknowledgementToken)
  75. return acknowledgementToken
  76. }
  77. }