From ea23cc7e4a52ca2aaa1c512a2657becd2d5b642b Mon Sep 17 00:00:00 2001 From: Dominik Hebeler <dominik@suma-ev.de> Date: Fri, 18 Nov 2022 11:01:53 +0100 Subject: [PATCH] storing amount of signed receipts --- pass/app/Order.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/pass/app/Order.js b/pass/app/Order.js index fafabd5..2a13e2d 100644 --- a/pass/app/Order.js +++ b/pass/app/Order.js @@ -69,8 +69,7 @@ class Order { this.#order_path = path.join( this.#order_path, this.#order_date.format("YYYY"), - this.#order_date.format("MM"), - "orders" + this.#order_date.format("MM") ); this.#amount = parseInt(amount); @@ -128,11 +127,29 @@ class Order { async signOrder() { let mgcrypto = new Crypto(); + if (this.#signatures.length > 0) { + return false; + } + let signed_encrypted_sales_receipts = mgcrypto.sign( this.#encrypted_sales_receipts, this.#expires_at ); this.#signatures = await signed_encrypted_sales_receipts; + + // Store amount of signed receipts for our records + // So we know how much searches we have given out + let fs = require("fs"); + let generated_file = path.join(this.#order_path, "generated.json"); + // Create directory if it does not exist + if (!fs.existsSync(path.dirname(generated_file))) { + fs.mkdirSync(path.dirname(generated_file), { recursive: true }); + } + for (let i = 0; i < this.#signatures.length; i++) { + fs.appendFileSync(generated_file, this.#order_id + `_${i}\n`); + } + + return true; } static async LOAD_ORDER_FROM_ID(order_id) { @@ -220,6 +237,7 @@ class Order { let fs = require("fs"); let order_file = path.join( this.#order_path, + "orders", this.#order_id.toString() + ".json" ); // Create directory if it does not exist -- GitLab