Skip to content

Commit

Permalink
added .gitignore & added validation rules & fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ssortia committed Nov 4, 2024
1 parent c513c88 commit 876faf6
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ilb-kkmhub-client-*
node_modules
.idea
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
13 changes: 5 additions & 8 deletions src/Receipt.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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);
});

Expand Down Expand Up @@ -171,10 +169,9 @@ export default class Receipt {
};

/**
* Возвращает уникальный идентификатор под которым будет создана запись
* в kkmhub (и по которому эту запись можно будет получить)
* Возвращает уникальный идентификатор под которым будет создана запись в kkmhub
*
* @returns {string} - строка в формате uuidv4
* @returns {string} - строка длиной 32 символа
*/
getOperationId() {
this.#methodNotDefined("getOperationId");
Expand Down
4 changes: 4 additions & 0 deletions src/ReceiptValidator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
5 changes: 5 additions & 0 deletions src/example/ExampleReceipt.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 "Игрушки";
}
Expand Down
2 changes: 1 addition & 1 deletion src/example/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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";

0 comments on commit 876faf6

Please sign in to comment.