acknowledgement.service.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { AnyObject } from "mongoose";
  2. import { map, Observable, of, tap } from "rxjs";
  3. import { BaseMessage, 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 settings: LogSetting = {
  11. storage: '',
  12. setting: {
  13. appId: undefined,
  14. appName: '',
  15. logLocName: '',
  16. logLocId: undefined,
  17. appLogLocId: undefined,
  18. appLocName: '',
  19. appLogId: undefined
  20. }
  21. }
  22. constructor(private logService1?: LoggingService, private logService?: LoggingService) {
  23. // this.logService1 = new LoggingService()
  24. this.logService = new LoggingService()
  25. }
  26. public async init(settings: AcknowledgementLogSetting) {
  27. let logSetting: LogSetting = {
  28. ...settings,
  29. setting: {
  30. ...settings.setting,
  31. logLocName: "locationName2",
  32. appLocName: "appLocName2"
  33. }
  34. }
  35. this.settings = logSetting
  36. this.logService.init(logSetting)
  37. }
  38. public subscribe(obs: Observable<BaseMessage>): Observable<ResponseMessage> {
  39. let acknowledgementToken: Observable<ResponseMessage> = obs.pipe(
  40. map(
  41. incoming_msg => {
  42. let emulatedId = "GeneratedFromMessageSync"
  43. let emulatedRequest = this.messageUtil.getCommandMessage(emulatedId, Command.New, incoming_msg)
  44. let finalResponse = this.messageUtil.getResponseMessage(emulatedId, { "Acknowledgement": 1 }, emulatedRequest)
  45. return finalResponse
  46. }
  47. ))
  48. let acknowledgementTokenLogging: Observable<MessageLog> = obs.pipe(
  49. map(
  50. incoming_msg => {
  51. let finalResponse:MessageLog = {
  52. appLogLocId: new Uuid().generateId(),
  53. appData: {
  54. msgId: incoming_msg.header.messageID || new Uuid().generateId(),
  55. msgLogDateTime: new Date(),
  56. msgDateTime: new Date(),
  57. msgTag: ['Acknowledgement'],
  58. msgPayload: JSON.stringify(incoming_msg)
  59. }
  60. }
  61. return finalResponse
  62. }
  63. )
  64. )
  65. this.logService.subscribe(acknowledgementTokenLogging)
  66. return acknowledgementToken
  67. }
  68. }