UNPKG

vista-co

Version:
340 lines (339 loc) 16.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Booking = void 0; //Booking.ts const axios_master_1 = require("axios-master"); const Booking = (config) => { return { // Function to get booking details GetBookingDetails: async (requestBody) => { var _a, _b, _c; try { const url = `${config.host}/WSVistaWebClient/OData.svc/Booking`; const res = await (0, axios_master_1.axiosMasterMain)({ method: "POST", url, headers: { connectapitoken: `${config.token}`, "Content-Type": "application/json", "Connect-Region-Code": config.regionCode, }, data: requestBody, }, { name: "GetBookingDetails", timeout: 20000, }); return { success: true, message: "Request successful", data: res, }; } catch (error) { console.error("Request failed", (_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.data); return { success: false, message: ((_c = (_b = error === null || error === void 0 ? void 0 : error.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.message) || "An error occurred", }; } }, // Function to cancel a booking CancelBooking: async (requestBody) => { var _a, _b, _c; try { const url = `${config.host}/WSVistaWebClient/OData.svc/booking/cancel`; const res = await (0, axios_master_1.axiosMasterMain)({ method: "POST", url, headers: { connectapitoken: `${config.token}`, "Content-Type": "application/json", "Connect-Region-Code": config.regionCode, }, data: requestBody, }, { name: "CancelBooking", timeout: 20000, }); return { success: true, message: "Booking cancelled successfully", data: res, }; } catch (error) { console.error("Cancel booking failed", (_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.data); return { success: false, message: ((_c = (_b = error === null || error === void 0 ? void 0 : error.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.message) || "An error occurred while cancelling the booking", }; } }, // Function to mark a booking as collected MarkBookingAsCollected: async (requestBody) => { var _a, _b, _c; try { const url = `${config.host}/WSVistaWebClient/OData.svc/booking/markcollected`; const res = await (0, axios_master_1.axiosMasterMain)({ method: "POST", url, headers: { connectapitoken: `${config.token}`, "Content-Type": "application/json", "Connect-Region-Code": config.regionCode, }, data: requestBody, }, { name: "MarkBookingAsCollected", timeout: 20000, }); return { success: true, message: "Booking marked as collected successfully", data: res, }; } catch (error) { console.error("Mark booking as collected failed", (_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.data); return { success: false, message: ((_c = (_b = error === null || error === void 0 ? void 0 : error.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.message) || "An error occurred while marking the booking as collected", }; } }, // Function to refund a booking RefundBooking: async (requestBody) => { var _a, _b, _c; try { const url = `${config.host}/WSVistaWebClient/OData.svc/booking/refund`; const res = await (0, axios_master_1.axiosMasterMain)({ method: "POST", url, headers: { connectapitoken: `${config.token}`, "Content-Type": "application/json", "Connect-Region-Code": config.regionCode, }, data: requestBody, }, { name: "RefundBooking", timeout: 20000, }); return { success: true, message: "Booking refunded successfully", data: res, }; } catch (error) { console.error("Refund booking failed", (_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.data); return { success: false, message: ((_c = (_b = error === null || error === void 0 ? void 0 : error.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.message) || "An error occurred while processing the refund", }; } }, // Function to search for bookings SearchBooking: async (requestBody) => { var _a, _b, _c; try { const url = `${config.host}/WSVistaWebClient/OData.svc/booking/search`; const res = await (0, axios_master_1.axiosMasterMain)({ method: "POST", url, headers: { connectapitoken: `${config.token}`, "Content-Type": "application/json", "Connect-Region-Code": config.regionCode, }, data: requestBody, }, { name: "SearchBooking", timeout: 20000, }); return { success: true, message: "Booking search successful", data: res, }; } catch (error) { console.error("Search booking failed", (_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.data); return { success: false, message: ((_c = (_b = error === null || error === void 0 ? void 0 : error.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.message) || "An error occurred", }; } }, // Function to retrieve the payment status on an unpaid booking GetUnpaidBookingDetails: async (token) => { var _a, _b, _c; try { // Construct the request URL with the token const url = `${config.host}/RESTBooking.svc/booking/unpaid/${token}`; // Send the GET request with headers including API token and region code const res = await (0, axios_master_1.axiosMasterMain)({ method: "GET", url, headers: { connectapitoken: `${config.token}`, // API token for authentication "Content-Type": "application/json", // Ensure the response format is JSON "Connect-Region-Code": config.regionCode, // Region code if needed }, }, { name: "GetUnpaidBookingDetails", // Request identifier for logging and debugging timeout: 20000, // Timeout of 20 seconds for the request logger(data) { if (config.logger) { console.log(data); // Logs request data for debugging purposes } }, }); // Return the 'data' from the successful response return { success: true, message: "Request successful", data: res, }; } catch (error) { // Logs and returns an error message if the request fails console.error("Request failed", (_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.data); return { success: false, message: ((_c = (_b = error === null || error === void 0 ? void 0 : error.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.message) || "An error occurred", }; } }, // Function to mark an unpaid booking as paid MarkBookingAsPaid: async (requestBody) => { var _a, _b, _c; try { // Construct the request URL const url = `${config.host}/RESTBooking.svc/booking/unpaid/mark-paid`; // Send the POST request with the requestBody and headers const res = await (0, axios_master_1.axiosMasterMain)({ method: "POST", url, headers: { connectapitoken: `${config.token}`, // API token for authentication "Content-Type": "application/json", // Ensure the response format is JSON "Connect-Region-Code": config.regionCode, // Region code if needed }, data: requestBody, // Pass the body as JSON }, { name: "MarkBookingAsPaid", // For logging and debugging purposes timeout: 20000, // Timeout of 20 seconds for the request logger(data) { if (config.logger) { console.log(data); // Logs request data for debugging purposes } }, }); // Return the 'data' from the successful response return { success: true, message: "Booking marked as paid successfully", data: res, }; } catch (error) { // Logs and returns an error message if the request fails console.error("Marking booking as paid failed", (_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.data); return { success: false, message: ((_c = (_b = error === null || error === void 0 ? void 0 : error.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.message) || "An error occurred while marking the booking as paid", }; } }, // Function to start payment for an unpaid booking StartPaymentForUnpaidBooking: async (requestBody) => { var _a, _b, _c; try { // Construct the request URL const url = `${config.host}/RESTBooking.svc/booking/unpaid/start-redirect-payment`; // Send the POST request with the requestBody and headers const res = await (0, axios_master_1.axiosMasterMain)({ method: "POST", url, headers: { connectapitoken: `${config.token}`, // API token for authentication "Content-Type": "application/json", // Ensure the response format is JSON "Connect-Region-Code": config.regionCode, // Region code if needed }, data: requestBody, // Pass the body as JSON }, { name: "StartPaymentForUnpaidBooking", // For logging and debugging purposes timeout: 20000, // Timeout of 20 seconds for the request logger(data) { if (config.logger) { console.log(data); // Logs request data for debugging purposes } }, }); // Return the 'data' from the successful response return { success: true, message: "Payment started successfully", data: res, }; } catch (error) { // Logs and returns an error message if the request fails console.error("Payment start failed", (_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.data); return { success: false, message: ((_c = (_b = error === null || error === void 0 ? void 0 : error.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.message) || "An error occurred while starting payment", }; } }, // Function to update comments or hold flag on an unpaid booking UpdateUnpaidBooking: async (requestBody) => { var _a, _b, _c; try { // Construct the request URL const url = `${config.host}/RESTBooking.svc/booking/unpaid/update`; // Send the POST request with the requestBody and headers const res = await (0, axios_master_1.axiosMasterMain)({ method: "POST", url, headers: { connectapitoken: `${config.token}`, // API token for authentication "Content-Type": "application/json", // Ensure the response format is JSON "Connect-Region-Code": config.regionCode, // Region code if needed }, data: requestBody, // Pass the body as JSON }, { name: "UpdateUnpaidBooking", // For logging and debugging purposes timeout: 20000, // Timeout of 20 seconds for the request logger(data) { if (config.logger) { console.log(data); // Logs request data for debugging purposes } }, }); // Return the 'data' from the successful response return { success: true, message: "Booking updated successfully", data: res, }; } catch (error) { // Logs and returns an error message if the request fails console.error("Booking update failed", (_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.data); return { success: false, message: ((_c = (_b = error === null || error === void 0 ? void 0 : error.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.message) || "An error occurred while updating the booking", }; } }, }; }; exports.Booking = Booking;