UNPKG

@payburner/keyburner-sidewinder-core

Version:
104 lines 4.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AWSDynamoTransactionService = void 0; const npm_1 = require("@payburner/keyburner-sidewinder-model/dist/npm"); class AWSDynamoTransactionService { constructor(docClient) { this.docClient = null; this.docClient = docClient; } saveDecodedTransaction(decodedTransaction) { const comp = this; return new Promise((resolve, reject) => { const dataBody = decodedTransaction; const params = { TableName: 'sidewinder_transactions', Item: dataBody }; comp.docClient.put(params, function (err, data) { if (err) { resolve(false); } else { resolve(true); } }); }); } getProcessedTransaction(environment, id) { const self = this; return new Promise((resolve, reject) => { const params = { TableName: "sidewinder_transactions", KeyConditionExpression: "id = :id and environment = :environment", ExpressionAttributeValues: { ":id": id, ":environment": environment } }; console.log('Querying getProcessedTransaction:' + JSON.stringify(params, null, 2)); self.docClient.query(params, function (err, data) { if (err) { console.error("getProcessedTransaction :: Unable to query. Error:", JSON.stringify(err, null, 2)); reject(err); } else { if (data.Items.length === 0) { reject('getProcessedTransaction Not found.'); } else { resolve(data.Items[0]); } } }); }); } getTransactionsByEnvironmentAndProcessingStage(environment, processingStage) { const self = this; return new Promise((resolve, reject) => { const params = { TableName: "sidewinder_transactions", IndexName: "environment_processing_stage-timestamp-index", KeyConditionExpression: "environment_processing_stage = :environment_processing_stage ", ExpressionAttributeValues: { ":environment_processing_stage": environment + '_' + processingStage }, ScanIndexForward: true }; self.docClient.query(params, function (err, data) { if (err) { console.error("getTransactionsByEnvironmentAndProcessingStage :: Unable to query. Error:", JSON.stringify(err, null, 2)); reject(err); } else { resolve(data); } }); }); } getProcessedTransactions(environment, address) { const self = this; return new Promise((resolve, reject) => { const params = { TableName: "sidewinder_transactions", IndexName: "address_uri-sequence-index", KeyConditionExpression: "address_uri = :address_uri", ExpressionAttributeValues: { ":address_uri": npm_1.AccountUtils.calculateEnvironmentAddress(environment, address) }, ScanIndexForward: false }; self.docClient.query(params, function (err, data) { if (err) { console.error("getProcessedTransactions :: Unable to query. Error:", JSON.stringify(err, null, 2)); reject(err); } else { resolve(data); } }); }); } } exports.AWSDynamoTransactionService = AWSDynamoTransactionService; //# sourceMappingURL=AWSDynamoTransactionService.js.map