From 6c497587182d6d1a77b81954bef7f75f1f2754d1 Mon Sep 17 00:00:00 2001 From: Alex Step Date: Mon, 15 Mar 2021 04:01:04 +0300 Subject: [PATCH] upd licaense and .call method --- README.md | 2 +- docs/nalogAPIClass.md | 6 +++--- index.js | 8 +++++--- package.json | 4 ++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 279cd5d..426b8b6 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ const stats = await nalogAPI.call('incomes/summary') Пример расширенного добавления дохода ```javascript - const response = await nalogAPI.call('income', 'POST', { + const response = await nalogAPI.call('income', { paymentType: 'CASH', inn: null, ignoreMaxTotalIncomeRestriction: false, diff --git a/docs/nalogAPIClass.md b/docs/nalogAPIClass.md index 9400116..75834b1 100644 --- a/docs/nalogAPIClass.md +++ b/docs/nalogAPIClass.md @@ -31,7 +31,7 @@ * [.createDeviceId()](#NalogAPI+createDeviceId) * [.auth(username, password)](#NalogAPI+auth) ⇒ Promise(object) * [.getToken()](#NalogAPI+getToken) ⇒ Promise(string) - * [.call(endpoint, method, payload)](#NalogAPI+call) ⇒ Promise(object) + * [.call(endpoint, payload, method)](#NalogAPI+call) ⇒ Promise(object) * [.addIncome(date, name, amount)](#NalogAPI+addIncome) ⇒ Promise({id,printUrl,jsonUrl,data,approvedReceiptUuid}) * [.userInfo()](#NalogAPI+userInfo) ⇒ Promise(object) @@ -73,7 +73,7 @@ **Kind**: instance method of [NalogAPI](#NalogAPI) -### nalogAPI.call(endpoint, method, payload) ⇒ Promise(object) +### nalogAPI.call(endpoint, payload, method) ⇒ Promise(object) Вызов метода api **Kind**: instance method of [NalogAPI](#NalogAPI) @@ -82,8 +82,8 @@ | Param | Type | Default | Description | | --- | --- | --- | --- | | endpoint | string | | url метода без слэша в начале (например `user`) | -| method | enum | 'GET' | | | payload | object | | данные для отправки в body | +| method | enum | 'GET' | | diff --git a/index.js b/index.js index 6da70a8..61040aa 100644 --- a/index.js +++ b/index.js @@ -146,11 +146,13 @@ class NalogAPI { /** * Вызов метода api * @param {string} endpoint - url метода без слэша в начале (например `user`) - * @param {enum} method='GET' * @param {object} payload - данные для отправки в body + * @param {enum} method='GET' * @returns {Promise(object)} - json ответа сервера */ - async call (endpoint, method = 'GET', payload = {}) { + async call (endpoint, payload, method = 'GET') { + if (payload) { method = 'POST' } + const params = { method: method, headers: { @@ -179,7 +181,7 @@ class NalogAPI { * @returns {Promise({id,printUrl,jsonUrl,data,approvedReceiptUuid})} - информация о созданном чеке, либо об ошибке */ async addIncome ({ date = new Date(), name, quantity = 1, amount }) { - const response = await this.call('income', 'POST', { + const response = await this.call('income', { paymentType: 'CASH', inn: null, ignoreMaxTotalIncomeRestriction: false, diff --git a/package.json b/package.json index e8f6af7..19782d8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "moy-nalog", - "version": "1.0.2", + "version": "1.0.3", "description": "Обёртка для API сервиса lknpd.nalog.ru", "main": "index.js", "scripts": { @@ -13,7 +13,7 @@ }, "keywords": [], "author": "", - "license": "ISC", + "license": "MIT", "bugs": { "url": "https://github.com/alexstep/moy-nalog/issues" },