From 876faf6d2e46754c927b05b556bc85e9465316bb Mon Sep 17 00:00:00 2001 From: ssortia Date: Mon, 4 Nov 2024 19:14:41 +0300 Subject: [PATCH] added .gitignore & added validation rules & fixes --- .gitignore | 3 +++ package.json | 4 ++-- src/Receipt.mjs | 13 +++++-------- src/ReceiptValidator.mjs | 4 ++++ src/example/ExampleReceipt.mjs | 5 +++++ src/example/index.mjs | 2 +- src/index.js | 6 ++++++ 7 files changed, 26 insertions(+), 11 deletions(-) create mode 100644 .gitignore create mode 100644 src/index.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..47ca4c3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +ilb-kkmhub-client-* +node_modules +.idea \ No newline at end of file diff --git a/package.json b/package.json index ed6ca17..9080e54 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "@ilb/kkmhub-client", - "version": "1.0.1", + "version": "1.0.2", "description": "", - "main": "index.js", + "main": "src/index.js", "type": "module", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" diff --git a/src/Receipt.mjs b/src/Receipt.mjs index 86d7471..1b3fad1 100644 --- a/src/Receipt.mjs +++ b/src/Receipt.mjs @@ -8,11 +8,9 @@ import ReceiptValidator from "./ReceiptValidator.mjs"; export default class Receipt { /** * @param {string} applicationId - идентификатор организации - * @param {object} receiptData - любые данные */ - constructor({ applicationId, receiptData }) { + constructor({ applicationId }) { this.applicationId = applicationId; - this.receiptData = receiptData; this.validator = new ReceiptValidator(); } @@ -108,8 +106,8 @@ export default class Receipt { let amount = currency(0); positions.forEach(position => { - const curAmount = currency(position.amount); - const positionPrice = curAmount.multiply(position.quantity); + const positionAmount = currency(parseFloat(position.amount)); + const positionPrice = positionAmount.multiply(parseFloat(position.quantity)); amount = amount.add(positionPrice); }); @@ -171,10 +169,9 @@ export default class Receipt { }; /** - * Возвращает уникальный идентификатор под которым будет создана запись - * в kkmhub (и по которому эту запись можно будет получить) + * Возвращает уникальный идентификатор под которым будет создана запись в kkmhub * - * @returns {string} - строка в формате uuidv4 + * @returns {string} - строка длиной 32 символа */ getOperationId() { this.#methodNotDefined("getOperationId"); diff --git a/src/ReceiptValidator.mjs b/src/ReceiptValidator.mjs index 013f79e..96df58c 100644 --- a/src/ReceiptValidator.mjs +++ b/src/ReceiptValidator.mjs @@ -41,6 +41,10 @@ export default class ReceiptValidator { this.addError("Не заполнено поле operationId"); } + if (receiptData.operationId.length > 32) { + this.addError("Поле operationId должно быть не длиннее 32 символов"); + } + if (!receiptData.payTimeString) { this.addError("Не заполнено поле payTimeString"); } diff --git a/src/example/ExampleReceipt.mjs b/src/example/ExampleReceipt.mjs index 1f4d3f7..c6115a1 100644 --- a/src/example/ExampleReceipt.mjs +++ b/src/example/ExampleReceipt.mjs @@ -6,6 +6,11 @@ import ReceiptType from "../constants/ReceiptType.mjs"; import ReceiptSumType from "../constants/ReceiptSumType.mjs"; export default class ExampleReceipt extends Receipt { + constructor(receiptData) { + super({ applicationId: "project-name" }); + this.receiptData = receiptData; + } + getName() { return "Игрушки"; } diff --git a/src/example/index.mjs b/src/example/index.mjs index 6ad4fc8..3369316 100644 --- a/src/example/index.mjs +++ b/src/example/index.mjs @@ -27,7 +27,7 @@ const receiptData = { }, }; -const receipt = new ExampleReceipt({ applicationId: "project-name", receiptData }); +const receipt = new ExampleReceipt(receiptData); const formattedData = receipt.format(); console.log(formattedData); diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..c58bfda --- /dev/null +++ b/src/index.js @@ -0,0 +1,6 @@ +export { default as KkmService } from "./KkmService.mjs"; +export { default as PositionItemSign } from "./constants/PositionItemSign.mjs"; +export { default as PositionTypeSign } from "./constants/PositionTypeSign.mjs"; +export { default as PositionNdsType } from "./constants/PositionNdsType.mjs"; +export { default as ReceiptType } from "./constants/ReceiptType.mjs"; +export { default as ReceiptSumType } from "./constants/ReceiptSumType.mjs";