UNPKG

fedapay-cli

Version:
88 lines (87 loc) 3.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const command_1 = require("@oclif/command"); const fedapay_1 = require("fedapay"); const json_colorizer_1 = tslib_1.__importDefault(require("json-colorizer")); const cli_ux_1 = tslib_1.__importDefault(require("cli-ux")); const customers_1 = tslib_1.__importDefault(require("../customers")); const dataparse_1 = tslib_1.__importDefault(require("../../helpers/dataparse")); /** * CustomersUpdate class extending the superClass Customers */ class CustomersUpdate extends customers_1.default { async run() { /** * @param object * get flags value */ const { flags } = this.parse(CustomersUpdate); /** * @param string * api key value */ const apiKey = this.userConfig.read('secret_key', flags['api-key']); /** * @param string * environment type */ const environment = this.userConfig.read('environment', flags.environment); /** * @param number * store the customer id */ const id = flags.id; /** * @param object * result of transforming flags.data into Typescript Object */ const data = dataparse_1.default.transform(flags.data); /** * Set Apikey and environment to connect to fedapay */ fedapay_1.FedaPay.setApiKey(apiKey); fedapay_1.FedaPay.setEnvironment(environment); try { cli_ux_1.default.action.start('Updating transaction'); const customer = await fedapay_1.Customer.update(id, data); this.log(json_colorizer_1.default(JSON.stringify(customer, null, 2))); } catch (error) { this.error(error.message); } cli_ux_1.default.action.stop(); } } exports.default = CustomersUpdate; /** * @param string * Description of the command Custommers:update description */ CustomersUpdate.description = 'Update a customer.'; /** * @param object * Declaration of the command flags */ CustomersUpdate.flags = Object.assign(Object.assign({}, customers_1.default.flags), { id: command_1.flags.integer({ description: 'The customer ID.', required: true }), data: command_1.flags.string({ description: 'Data for the API request.', required: true, char: 'd', multiple: true, }), help: command_1.flags.help({ char: 'h', description: 'Help for customers:update command.' }) }); /** * @param string * Set the command usage for help */ CustomersUpdate.usage = 'customers:update [options]'; /** * @param string[] * some examples of the custommers update use for help */ CustomersUpdate.examples = [ 'customers:update --api-key=[API-KEY] --environment=[env] --id=[ID] -d email=johndoe@zot.com', 'customers:update --api-key=[API-KEY] --environment=[env] --id=[ID] -d email=johndoe@zot.com -d lastname=Doe', ];