UNPKG

tickethead-sdk

Version:

SDK for the Tickethead API

161 lines 6.06 kB
"use strict"; 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.TicketService = void 0; const query_string_1 = __importDefault(require("query-string")); const types_1 = require("../blockchain/types"); const query_1 = require("../common/query"); /** * Service class for ticket API calls. Requires an organizer to be set (call to `useOrganizer`) */ class TicketService { constructor(client, version) { this.client = client; this.version = version; } /** * Returns true if the service is reachable * Currently the * * @returns Services' online status */ health() { return __awaiter(this, void 0, void 0, function* () { try { const res = yield this.client.get(`event/health`); if (res.data.status === 'ok') { return { online: true }; } } catch (e) { // Do nothing } return { online: false }; }); } /** * Returns a ticket by its ID * * @param req ID of the order * @returns `Ticket` */ getTicket(req) { return __awaiter(this, void 0, void 0, function* () { const query = query_string_1.default.stringify({ with: !req.with ? undefined : (0, query_1.buildQuery)(req.with), }, { arrayFormat: 'comma', skipNull: true, skipEmptyString: true }); const res = yield this.client.get(`event/${this.version}/ticket/${req.id}?${query}`); return res.data.data; }); } /** * Returns a list of tickets accessible to the user * * @param req Filters * @returns `Ticket[]` Tickets which belong to the user */ getTickets(req) { return __awaiter(this, void 0, void 0, function* () { const query = query_string_1.default.stringify({ with: !req.with ? undefined : (0, query_1.buildQuery)(req.with), with_enrollment_id: req.withEnrollmentId, format: req.format, status: req.status, }, { arrayFormat: 'comma', skipNull: true, skipEmptyString: true }); const res = yield this.client.get(`event/${this.version}/ticket?${query}`); return res.data.data; }); } /** * Get ticket holder information together with the questionnaire attached to it * * @param ticketId * @param ticketHolderId */ getTicketHolder(ticketHolderId) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.get(`event/${this.version}/ticket/${ticketHolderId.ticketId}/ticket_holder/${ticketHolderId.id}?with=questionnaire.questionnaire_item.question`); return res.data.data; }); } /** * Creates a ticket holder for the specified ticket * * @param ticketId Id of the ticket for which the ticket holder gets created * @param holder Ticket holder information * @returns TicketHolder */ createTicketHolder(ticketId, holder) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.post(`event/${this.version}/ticket/${ticketId.id}/ticket_holder`, holder); return res.data.data; }); } /** * Creates a ticket holder for the specified ticket * * @param holder Ticket holder information * @returns TicketHolder */ updateTicketHolder(id, holder) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.patch(`event/${this.version}/ticket/${id.ticketId}/ticket_holder/${id.id}`, holder); return res.data.data; }); } /** * Returns a ticket transfer payload * * @param data Ticket ids and the new owner * @returns Payload to use for `sendTransaction` */ getTransferPayload(data) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.post(`event/${this.version}/ticket/transfer`, data); return { fcn: types_1.BlockchainFunction.TransferTicket, args: res.data.data, }; }); } /** * Returns the base64 encoded QR-Code image for a given ticket * * @param ticketId ID of ticket * @returns */ getQrCode(ticketId) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.post(`event/${this.version}/ticket/${ticketId.id}/qrcode`, { action: 'trx', fcn: 'ticket.invalidate', }); return res.data.data; }); } /** * Get ticket info based on the blockchain id * * @param blockchainTicket * @returns */ getTicketByBlockchainId(blockchainTicket) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.get(`event/${this.version}/ticket/bc/${blockchainTicket.id}`); return res.data.data; }); } } exports.TicketService = TicketService; //# sourceMappingURL=service.js.map