vista-co
Version:
346 lines (345 loc) • 14.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const __1 = require("..");
const axios_master_1 = require("axios-master");
// Function to get booking details
const GetBookingDetails = async (requestBody) => {
var _a, _b, _c;
try {
const url = `${__1.config.host}/WSVistaWebClient/OData.svc/Booking`;
const res = await (0, axios_master_1.axiosMasterMain)({
method: "POST",
url,
headers: {
connectapitoken: `${__1.config.token}`,
"Content-Type": "application/json",
"Connect-Region-Code": __1.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
const CancelBooking = async (requestBody) => {
var _a, _b, _c;
try {
const url = `${__1.config.host}/WSVistaWebClient/OData.svc/booking/cancel`;
const res = await (0, axios_master_1.axiosMasterMain)({
method: "POST",
url,
headers: {
connectapitoken: `${__1.config.token}`,
"Content-Type": "application/json",
"Connect-Region-Code": __1.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
const MarkBookingAsCollected = async (requestBody) => {
var _a, _b, _c;
try {
const url = `${__1.config.host}/WSVistaWebClient/OData.svc/booking/markcollected`;
const res = await (0, axios_master_1.axiosMasterMain)({
method: "POST",
url,
headers: {
connectapitoken: `${__1.config.token}`,
"Content-Type": "application/json",
"Connect-Region-Code": __1.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
const RefundBooking = async (requestBody) => {
var _a, _b, _c;
try {
const url = `${__1.config.host}/WSVistaWebClient/OData.svc/booking/refund`;
const res = await (0, axios_master_1.axiosMasterMain)({
method: "POST",
url,
headers: {
connectapitoken: `${__1.config.token}`,
"Content-Type": "application/json",
"Connect-Region-Code": __1.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
const SearchBooking = async (requestBody) => {
var _a, _b, _c;
try {
const url = `${__1.config.host}/WSVistaWebClient/OData.svc/booking/search`;
const res = await (0, axios_master_1.axiosMasterMain)({
method: "POST",
url,
headers: {
connectapitoken: `${__1.config.token}`,
"Content-Type": "application/json",
"Connect-Region-Code": __1.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
const GetUnpaidBookingDetails = async (token // The required token for the unpaid booking
) => {
var _a, _b, _c;
try {
// Construct the request URL with the token
const url = `${__1.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: `${__1.config.token}`, // API token for authentication
"Content-Type": "application/json", // Ensure the response format is JSON
"Connect-Region-Code": __1.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 (__1.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
const MarkBookingAsPaid = async (requestBody) => {
var _a, _b, _c;
try {
// Construct the request URL
const url = `${__1.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: `${__1.config.token}`, // API token for authentication
"Content-Type": "application/json", // Ensure the response format is JSON
"Connect-Region-Code": __1.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 (__1.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
const StartPaymentForUnpaidBooking = async (requestBody) => {
var _a, _b, _c;
try {
// Construct the request URL
const url = `${__1.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: `${__1.config.token}`, // API token for authentication
"Content-Type": "application/json", // Ensure the response format is JSON
"Connect-Region-Code": __1.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 (__1.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
const UpdateUnpaidBooking = async (requestBody) => {
var _a, _b, _c;
try {
// Construct the request URL
const url = `${__1.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: `${__1.config.token}`, // API token for authentication
"Content-Type": "application/json", // Ensure the response format is JSON
"Connect-Region-Code": __1.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 (__1.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.default = {
GetBookingDetails,
CancelBooking,
MarkBookingAsCollected,
RefundBooking,
SearchBooking,
GetUnpaidBookingDetails,
MarkBookingAsPaid,
StartPaymentForUnpaidBooking,
UpdateUnpaidBooking,
};