UNPKG

@batlify/mscms2-api

Version:

MineStoreCMS v3 API package

114 lines (113 loc) 2.98 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const context_1 = __importDefault(require("../../core/context")); const packages_1 = __importDefault(require("./packages")); class Cart extends context_1.default { constructor() { super(); this.packages = new packages_1.default(); } /* * Get cart's data * @Note Authorization is needed * @param response * @throws Error */ async getCart() { return this.request(true, 'POST', '/cart/get') .then((response) => { return response; }) .catch((e) => { throw e; }); } /* * Check if cart is empty * @Note Authorization is needed * @param response * @throws Error */ async isCartEmpty() { return this.request(true, 'POST', '/cart/get') .then((response) => { return response.items.length === 0; }) .catch((e) => { throw e; }); } /* * Add package to cart * @Note Authorization is needed * @param response * @throws Error */ async addPackage(id, promoted, payment_type) { return this.packages.add(id, promoted, payment_type); } /* * Remove package from cart * @Note Authorization is needed * @param response * @throws Error */ async removePackage(id) { return this.packages.remove(id); } /* * Update package's quantity in cart * @Note Authorization is needed * @param response * @throws Error */ async quantityPackage(id, quantity) { return this.packages.quantity(id, quantity); } /* * Update package's price in cart * @Note Authorization is needed * @param response * @throws Error */ async pricePackage(id, price) { return this.packages.price(id, price); } /* * Update package's variable in cart * @Note Authorization is needed * @param response * @throws Error */ async variablePackage(id, variable, value) { return this.packages.variable(id, variable, value); } /* * Update package's variable in cart * @Note Authorization is needed * @param response * @throws Error */ async selectServerPackage(id, server) { return this.packages.selectServer(id, server); } /* * Get selectable servers * @Note Authorization is needed * @param response * @throws Error */ async getSelectableServers() { return this.request(true, 'POST', '/cart/getSelectServers') .then((response) => { return response; }) .catch((e) => { throw e; }); } } exports.default = Cart;