UNPKG

asksuite-core

Version:
144 lines (131 loc) 3.32 kB
const requestPromise = require('request-promise-native'); const Global = require('./global'); module.exports = function (config) { const requester = {}; const AsksuiteService = require('./infochat.service')(config); requester.search = async function ( type, idHotel, checkin, checkout, adultos, criancas, cupom, childAges, otherParams, quotationIdentifier, ) { try { // vai buscar no nosso banco de dados os motores registrados com o type X; const BookingEngine = await AsksuiteService.findBookingEngineByType(type); const options = { uri: Global.CRAWLER_ENDPOINT + '/generic/' + BookingEngine.urlPath, qs: { idHotel, checkin, checkout, adultos, criancas, cupom, childAges, otherParams, quotationIdentifier, }, json: true, // Automatically parses the JSON string in the response }; const response = await requestPromise.get(options); return Promise.resolve(response); } catch (err) { console.log('caiu aqui no erro'); console.error(err.error); return Promise.reject(err.error); } }; requester.searchByMultipleCompanies = async function ( checkin, checkout, adultos, criancas, childAges, dataHotels, ) { return new Promise((resolve, reject) => { Promise.all( dataHotels.map(({ companyId, company, idHotel, type, code, otherParams, dialog }) => { return requester .search( type, idHotel, checkin, checkout, adultos, criancas, code, childAges, otherParams, ) .then((data) => { return { companyId, company, data, dialog, }; }) .catch((error) => { return { companyId, company, error, dialog, }; }); }), ) .then((data) => { resolve(data); }) .catch((error) => { console.log('error', error); reject(error); }); }); }; requester.getSuggestionDates = async function ( type, idHotel, checkin, checkout, adultos, criancas, cupom, childAges, otherParams, ) { try { const BookingEngine = await AsksuiteService.findBookingEngineByType(type); const options = { uri: Global.CRAWLER_ENDPOINT + '/generic/generic/suggestion', qs: { idHotel, checkin, checkout, adultos, criancas, cupom, childAges, otherParams, crawlerName: BookingEngine.urlPath, }, json: true, // Automatically parses the JSON string in the response }; const response = await requestPromise.get(options); return Promise.resolve(response); } catch (err) { console.log('caiu aqui no erro'); console.error(err.error); return Promise.reject(err.error); } }; return requester; };