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EACJ,CACD","names":["EventStore","EventEmitter","cb","payload","instance","FollowTypes","ResultTypeEnums","subscribe","user_authentication_handle","neighbourhood_id","follow_type","Promise","__vitePreload","Routes","q_ajax_3","I18n","http_status_code","AJAX_ERROR_HANDLER_ACTIONS","reason_or_error","response"],"ignoreList":[],"sources":["../../../app/assets/javascripts/app/resources/neighbourhood_followings/event_store/index.ts","../../../app/assets/javascripts/app/resources/neighbourhood_followings/subscribe/index.ts"],"sourcesContent":["\n// region JS Imports\n\n// region External Modules\nimport { EventEmitter } from \"events\"\n// endregion External Modules\n\n// Private Modules\n// Private Modules\n\n// region Public Components\n// endregion Public Components\n\n// region Private Components\n// endregion Private Components\n\n// endregion JS Imports\n\n/* eslint-disable no-unused-vars */\nenum EventTypes {\n  SUBSCRIBE   = \"subscribe\",\n  UNSUBSCRIBE = \"unsubscribe\",\n}\n/* eslint-enable no-unused-vars */\n\ninterface SubscribeEventPayload {\n  neighbourhood_id: string | number,\n  follow_type:      string,\n}\ninterface UnsubscribeEventPayload {\n  neighbourhood_id: string | number,\n  follow_type:      string,\n}\n\nclass EventStore {\n  private readonly event_emitter: EventEmitter\n\n  constructor() {\n    this.event_emitter = new EventEmitter()\n  }\n\n  public onSubscribe(cb: (payload: SubscribeEventPayload) => void) {\n    this.event_emitter.on(EventTypes.SUBSCRIBE, cb)\n  }\n  public fireSubscribeEvent(payload: SubscribeEventPayload) {\n    this.event_emitter.emit(EventTypes.SUBSCRIBE, payload)\n  }\n\n  public onUnsubscribe(cb: (payload: UnsubscribeEventPayload) => void) {\n    this.event_emitter.on(EventTypes.UNSUBSCRIBE, cb)\n  }\n  public fireUnsubscribeEvent(payload: UnsubscribeEventPayload) {\n    this.event_emitter.emit(EventTypes.UNSUBSCRIBE, payload)\n  }\n}\n\nconst instance = new EventStore()\n\nexport default instance\n","\nimport Promise from \"bluebird\"\nimport {\n  q_ajax_3,\n  ERROR_HANDLER_ACTIONS as AJAX_ERROR_HANDLER_ACTIONS,\n} from \"app/utils/q_ajax/q_ajax_3\"\n\n\nimport I18n from \"plugins/i18n-js\"\n\n\n/* eslint-disable no-unused-vars */\nexport enum FollowTypes {\n  RESIDENTIAL = \"residential\",\n  COMMERCIAL  = \"commercial\",\n}\n/* eslint-enable no-unused-vars */\n\ninterface Input {\n  user_authentication_handle: string,\n\n  neighbourhood_id: string | number,\n\n  follow_type: FollowTypes,\n}\n\n/* eslint-disable no-unused-vars */\nenum ResultTypeEnums {\n  SUCCESS = \"SUCCESS\",\n  UNAUTHENTICATED = \"UNAUTHENTICATED\",\n  INVALID = \"INVALID\",\n  SERVER_ERROR = \"SERVER_ERROR\",\n}\n/* eslint-enable no-unused-vars */\n\ninterface PromiseResolvePayload {\n  result_type: ResultTypeEnums,\n  data?: {},\n}\n\nconst subscribe = ({user_authentication_handle, neighbourhood_id, follow_type}: Input): Promise<any> => {\n  return Promise.resolve(\n    import(\n      \"plugins/js-routes\"\n    )\n  )\n  .then((Routes) => {\n    return q_ajax_3(\n      {\n        url:      Routes.subscribe_api_web_app_neighbourhood_followings_path(),\n        type:     \"POST\",\n\n        // Expect JSON in response\n        dataType: \"JSON\",\n\n        // Sending JSON to server\n        contentType:  \"application/json; charset=utf-8\",\n        data:         JSON.stringify({\n          user_authentication_handle: user_authentication_handle,\n          neighbourhood_id:           neighbourhood_id,\n          follow_type:                follow_type,\n\n          locale: I18n.locale,\n        }),\n      },\n      {\n        custom_error_handler: ({http_status_code}) => {\n          if (http_status_code === 401) {\n            return AJAX_ERROR_HANDLER_ACTIONS.STOP_RETRY\n          }\n          if (http_status_code === 422) {\n            return AJAX_ERROR_HANDLER_ACTIONS.STOP_RETRY\n          }\n\n          return AJAX_ERROR_HANDLER_ACTIONS.CONTINUE_RETRY\n        },\n      },\n    )\n  })\n  .then(() => {\n    return (\n      {\n        result_type: ResultTypeEnums.SUCCESS,\n        data: {},\n      }\n    )\n  })\n  .catch((reason_or_error) => {\n    if (reason_or_error instanceof Error) {\n      throw reason_or_error\n    }\n\n    const { response } = reason_or_error\n    switch (response.status) {\n      case 500:\n      case 502:\n      case 503:\n      case 504:\n        return ({\n          result_type: ResultTypeEnums.SERVER_ERROR,\n        })\n      case 401:\n        return ({\n          result_type: ResultTypeEnums.UNAUTHENTICATED,\n        })\n      case 422:\n        return ({\n          result_type: ResultTypeEnums.INVALID,\n        })\n      default:\n        return ({\n          result_type: ResultTypeEnums.INVALID,\n        })\n    }\n  })\n}\n\nexport {\n  subscribe,\n  ResultTypeEnums,\n}\n"],"file":"assets/index-HFhgRjAd.js"}