diff --git a/pass/app/Order.js b/pass/app/Order.js index fafabd5844a0201f95baefd572320a3e54ec6d33..2a13e2de1e33595c7b437ac0a8cd70473de95a1e 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