tickethead-sdk
Version:
SDK for the Tickethead API
107 lines • 3.99 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.VenueService = void 0;
const query_string_1 = __importDefault(require("query-string"));
/**
* Service class for venue service API calls.
*/
class VenueService {
constructor(client, version) {
this.client = client;
this.version = version;
}
/**
* Returns true if the service is reachable
*
* @returns Services' online status
*/
health() {
return __awaiter(this, void 0, void 0, function* () {
try {
const res = yield this.client.get(`venue/health`);
if (res.data.status === 'ok') {
return { online: true };
}
}
catch (e) {
// Do nothing
}
return { online: false };
});
}
/**
* Gets venues matching specified criteria.
*
* @param req filtering options
* @returns an array of venues matching the criteria
*/
getVenues() {
return __awaiter(this, arguments, void 0, function* (req = {}) {
const query = query_string_1.default.stringify(Object.assign(Object.assign({}, req), { q: req.query, sort_by: req.sortBy, with: 'address.position' }), { arrayFormat: 'comma' });
const res = yield this.client.get(`venue/${this.version}/venue?${query}`);
return res.data.data;
});
}
/**
* Gets a venue by its id.
*
* @param req venue ID and query options
* @returns the requested venue
*/
getVenue(options) {
return __awaiter(this, void 0, void 0, function* () {
const query = query_string_1.default.stringify(Object.assign(Object.assign({}, options), { q: options.query, sort_by: options.sortBy, with: 'address.position' }), { arrayFormat: 'comma' });
const res = yield this.client.get(`venue/${this.version}/venue/${options.id}?${query}`);
return res.data.data;
});
}
/**
* Creates a new venue
*
* @param newVenue venue data
* @returns the created venue
*/
createVenue(newVenue) {
return __awaiter(this, void 0, void 0, function* () {
const res = yield this.client.post(`venue/${this.version}/venue`, newVenue);
return res.data.data;
});
}
/**
* Updates a venue
*
* @param newData venue data, must contain the venue id
* @returns the updated venue
*/
updateVenue(newData) {
return __awaiter(this, void 0, void 0, function* () {
const res = yield this.client.patch(`venue/${this.version}/venue/${newData.id}`, newData);
return res.data.data;
});
}
/**
* Updates a venue
*
* @param newData venue data, must contain the venue id
* @returns the updated venue
*/
deleteVenue(newData) {
return __awaiter(this, void 0, void 0, function* () {
yield this.client.delete(`venue/${this.version}/venue/${newData.id}`);
});
}
}
exports.VenueService = VenueService;
//# sourceMappingURL=service.js.map