UNPKG

@batlify/mscms2-api

Version:

MineStoreCMS v3 API package

63 lines (62 loc) 1.86 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 giftcards_1 = __importDefault(require("./giftcards")); const coupons_1 = __importDefault(require("./coupons")); class Discounts extends context_1.default { constructor() { super(); this.giftCards = new giftcards_1.default(); this.coupons = new coupons_1.default(); } /* * Check discount * @param type giftcard | coupon * @param code giftcard/coupon code * @throws Error */ async check(type, code) { if (type === 'giftcard') { if (!code) { throw new Error('Code is required'); } return this.giftCards.check(code); } if (type === 'coupon') { // why tf can't I check specific coupon code and coupon must be applied? // don't ask me why... it's just how it works ¯\_(ツ)_/¯ return this.coupons.check(); } } /* * Apply discount * @param code coupon code * @throws Error */ async apply(code) { return this.request(true, 'POST', '/cart/acceptCoupon', { coupon: code }) .then((response) => { return response; }) .catch((e) => { throw e; }); } /* * Remove discount * @param type giftcard | coupon * @throws Error */ async remove(type) { if (type === 'giftcard') { return this.giftCards.remove(); } if (type === 'coupon') { return this.coupons.remove(); } } } exports.default = Discounts;