acknowledgement.service.ts 2.9 KB

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