UNPKG

trade360-nodejs-sdk

Version:
277 lines 13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MetadataHttpClient = void 0; const enums_1 = require("../enums"); const validators_1 = require("../validators"); const _httpClient_1 = require("../../base-http-client"); const requests_1 = require("../../common/metadata/requests"); const responses_1 = require("../../common/metadata/responses"); const { GET_COMPETITIONS_PREFIX_URL, GET_LEAGUES_PREFIX_URL, GET_LOCATIONS_PREFIX_URL, GET_MARKETS_PREFIX_URL, GET_SPORTS_PREFIX_URL, GET_TRANSLATION_PREFIX_URL, GET_INCIDENT_PREFIX_URL, GET_VENUES_PREFIX_URL, GET_CITIES_PREFIX_URL, GET_STATES_PREFIX_URL, GET_PARTICIPANTS_PREFIX_URL, } = enums_1.MetadataRoutesPrefixUrl; /** * MetadataHttpClient class is responsible for sending requests * to the metadata API. It extends the BaseHttpClient class and * contains the logic for sending requests to the metadata API. * @param packageCredentials The package credentials for the API * @param restApiBaseUrl The base URL of the customers API * @param logger The logger instance * @param mapper The mapper instance * @returns MetadataHttpClient instance that is responsible for * sending requests to the metadata API. * @extends BaseHttpClient class for sending requests to the * customers API. * @implements IMetadataHttpClient interface for sending * requests to the metadata API. * @see BaseHttpClient class for sending requests to the * customers API. * @see IMetadataHttpClient interface for sending requests to * the metadata API. * @see IHttpServiceConfig interface for the configuration of * the HTTP service. */ class MetadataHttpClient extends _httpClient_1.BaseHttpClient { constructor({ packageCredentials, restApiBaseUrl, logger }, mapper) { super({ restApiBaseUrl, packageCredentials, logger }); this.mapper = mapper; } /** * getLocations method is responsible for sending a request * to the metadata API to get the locations. It sends a POST * request to the metadata API with the GET_LOCATIONS_PREFIX_URL * and LocationsCollectionResponse as the response type. * If the request is without "languageId" - the response returns * a list of "id" and "name" in English. * If The request is with "languagesId" that invalid - ErrorCode * 400 and error message - "Incorrect request, please enter a * valid Language and resend your request." * If the request is with "languageId" and there are some sports * that don't have a translation in this language - it's not * returned (without an error). * @returns A promise that contains the locations. * @throws Error if mapping configuration is not found or if the * request is invalid or incorrect. */ async getLocations() { const locationsCollection = await this.postRequest({ route: GET_LOCATIONS_PREFIX_URL, responseBodyType: responses_1.LocationsCollectionResponse, }); return locationsCollection?.locations; } /** * getSports method is responsible for sending a request * to the metadata API to get the sports. It sends a POST * request to the metadata API with the GET_SPORTS_PREFIX_URL * and SportsCollectionResponse as the response type. * If the request is without "languageId" - the response * returns a list of "id" and "name" in English. * If The request is with "languagesId" that invalid - * ErrorCode 400 and error message - "Incorrect request, * please enter a valid Language and resend your request." * If the request is with "languageId" and there are some * sports that don't have a translation in this language - * it's not returned (without an error). * @returns A promise that contains the sports. * @throws Error if mapping configuration is not found or * if the request is invalid or incorrect. */ async getSports() { const sportsCollection = await this.postRequest({ route: GET_SPORTS_PREFIX_URL, responseBodyType: responses_1.SportsCollectionResponse, }); return sportsCollection?.sports; } /** * getLeagues method is responsible for sending a request * to the metadata API to get the leagues. * It sends a POST request to the metadata API with the * GET_LEAGUES_PREFIX_URL and LeaguesCollectionResponse as * the response type. * If the request is without "languageId" - the response * returns a list of "id" and "name" in English. * If The request is with "languagesId" that invalid - * ErrorCode 400 and error message - "Incorrect request, * please enter a valid Language and resend your request." * If the request is with "LanguageId" and there are some * sports that don't have a translation in this language - * it's not returned (without an error). * @param requestDto The request DTO * @returns A promise that contains the leagues. * @throws Error if mapping configuration is not found or * if the request is invalid or incorrect. */ async getLeagues(requestDto) { const request = this.mapper.map(requestDto, requests_1.GetLeaguesRequest); const leaguesCollection = await this.postRequest({ route: GET_LEAGUES_PREFIX_URL, responseBodyType: responses_1.LeaguesCollectionResponse, requestBody: request, }); return leaguesCollection?.leagues; } /** * getMarkets method is responsible for sending a request * to the metadata API to get the markets. It sends a POST * request to the metadata API with the GET_MARKETS_PREFIX_URL * and MarketsCollectionResponse as the response type. * If the request is without "languageId" - the response * returns a list of "id" and "name" in English. * If The request is with "languagesId" that invalid - * ErrorCode 400 and error message - "Incorrect request, * please enter a valid Language and resend your request." * If the request is with "LanguageId" and there are some * sports that don't have a translation in this language - * it's not returned (without an error). * @param requestDto The request DTO for getting markets * from the metadata API. * @returns A promise that contains the markets. * @throws Error if mapping configuration is not found or * if the request is invalid or incorrect. */ async getMarkets(requestDto) { const request = this.mapper.map(requestDto, requests_1.GetMarketsRequest); const marketsCollection = await this.postRequest({ route: GET_MARKETS_PREFIX_URL, responseBodyType: responses_1.MarketsCollectionResponse, requestBody: request, }); return marketsCollection?.markets; } /** * getTranslations method is responsible for sending a request * to the metadata API to get the translations. It sends a POST * request to the metadata API with the GET_TRANSACTIONS_PREFIX_URL * and TransactionsCollectionResponse as the response type. If the * request does not have any optional field to translate- the * response will return an ErrorCode 400 and the message will * include the error. If the request is without Languages field - * the response will return an error with an informative message. */ async getTranslations(requestDto) { const request = this.mapper.map(requestDto, requests_1.GetTranslationsRequest); await validators_1.GetTranslationsRequestValidator.validate(request); const translationsCollection = await this.postRequest({ route: GET_TRANSLATION_PREFIX_URL, responseBodyType: responses_1.TranslationsCollectionResponse, requestBody: request, }); return translationsCollection; } /** * getCompetitions method is responsible for sending a request * to the metadata API to get the competitions. It sends a POST * request to the metadata API with the GET_COMPETITIONS_PREFIX_URL * and CompetitionCollectionResponse as the response type. */ async getCompetitions(requestDto) { const request = this.mapper.map(requestDto, requests_1.GetCompetitionsRequest); const competitionsCollection = await this.postRequest({ route: GET_COMPETITIONS_PREFIX_URL, responseBodyType: responses_1.CompetitionCollectionResponse, requestBody: request, }); return competitionsCollection; } /** * getIncidents method is responsible for sending a request * to the metadata API to get the incidents. * It sends a POST request to the metadata API with the * GET_INCIDENT_PREFIX_URL and IncidentsCollectionResponse * as the response type. * @param requestDto The request DTO for getting incidents * from the metadata API. * @returns A promise that contains the incidents data and total count. * @throws Error if the request is invalid or incorrect. */ async getIncidents(requestDto) { const request = this.mapper.map(requestDto, requests_1.GetIncidentsRequest); const response = await this.postRequest({ route: GET_INCIDENT_PREFIX_URL, responseBodyType: responses_1.IncidentsCollectionResponse, requestBody: request, }); return response; } /** * getVenues method is responsible for sending a request * to the metadata API to get the venues. * It sends a POST request to the metadata API with the * GET_VENUES_PREFIX_URL and VenuesCollectionResponse * as the response type. * @param requestDto The request DTO for getting venues * from the metadata API. * @returns A promise that contains the venues data and total count. * @throws Error if the request is invalid or incorrect. */ async getVenues(requestDto) { const request = this.mapper.map(requestDto, requests_1.GetVenuesRequest); const response = await this.postRequest({ route: GET_VENUES_PREFIX_URL, responseBodyType: responses_1.VenuesCollectionResponse, requestBody: request, }); return response; } /** * getCities method is responsible for sending a request * to the metadata API to get the cities. * It sends a POST request to the metadata API with the * GET_CITIES_PREFIX_URL and CitiesCollectionResponse * as the response type. * @param requestDto The request DTO for getting cities * from the metadata API. * @returns A promise that contains the cities data and total count. * @throws Error if the request is invalid or incorrect. */ async getCities(requestDto) { const request = this.mapper.map(requestDto, requests_1.GetCitiesRequest); const response = await this.postRequest({ route: GET_CITIES_PREFIX_URL, responseBodyType: responses_1.CitiesCollectionResponse, requestBody: request, }); return response; } /** * getStates method is responsible for sending a request * to the metadata API to get the states. * It sends a POST request to the metadata API with the * GET_STATES_PREFIX_URL and StatesCollectionResponse * as the response type. * @param requestDto The request DTO for getting states * from the metadata API. * @returns A promise that contains the states data and total count. * @throws Error if the request is invalid or incorrect. */ async getStates(requestDto) { const request = this.mapper.map(requestDto, requests_1.GetStatesRequest); const response = await this.postRequest({ route: GET_STATES_PREFIX_URL, responseBodyType: responses_1.StatesCollectionResponse, requestBody: request, }); return response; } /** * getParticipants method is responsible for sending a request * to the metadata API to get the participants. * It sends a POST request to the metadata API with the * GET_PARTICIPANTS_PREFIX_URL and ParticipantsCollectionResponse * as the response type. * @param requestDto The request DTO for getting participants * from the metadata API. * @returns A promise that contains the participants data and total count. * @throws Error if the request is invalid or incorrect. */ async getParticipants(requestDto) { const request = this.mapper.map(requestDto, requests_1.GetParticipantsRequest); const response = await this.postRequest({ route: GET_PARTICIPANTS_PREFIX_URL, responseBodyType: responses_1.ParticipantsCollectionResponse, requestBody: request, }); return response; } } exports.MetadataHttpClient = MetadataHttpClient; //# sourceMappingURL=metadata.service.js.map