|
|
|
@ -49,6 +49,7 @@ const transactionDataService = new (function TransactionDataService() {
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const getTransactionsByIdResults = (idResults) => { |
|
|
|
|
console.log("getTransactionsByIdResults") |
|
|
|
|
const idsSet = {}; |
|
|
|
|
const range = idResults.reduce((accum, keyValue) => { |
|
|
|
|
const id = keyValue.value; |
|
|
|
@ -66,6 +67,7 @@ const transactionDataService = new (function TransactionDataService() {
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const getSearchIndexForTransactions = (txs) => { |
|
|
|
|
console.log("getSearchIndexFor "+txs.length+" Transactions") |
|
|
|
|
const tokensSet = txs.map(searchTokenize) |
|
|
|
|
.reduce((accum, tokens) => { |
|
|
|
|
tokens.forEach(token => accum[token] = true);
|
|
|
|
@ -85,6 +87,7 @@ const transactionDataService = new (function TransactionDataService() {
|
|
|
|
|
)); |
|
|
|
|
} else { |
|
|
|
|
getAlreadyExistingTokenRecords = db.keyPrefix(keyPrefixTxCategorySearchIndex).then(keyValues => { |
|
|
|
|
console.log("getAlreadyExistingTokenRecords") |
|
|
|
|
const toReturn = []; |
|
|
|
|
let j = 0; |
|
|
|
|
let i = 0; |
|
|
|
@ -114,6 +117,7 @@ const transactionDataService = new (function TransactionDataService() {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const transactionWithViewPropertiesRemoved = (tx) => { |
|
|
|
|
console.log("transactionWithViewPropertiesRemoved") |
|
|
|
|
const toReturn = {}; |
|
|
|
|
Object.entries(tx).forEach(tuple => { |
|
|
|
|
if(tuple[0].indexOf('view') != 0) { |
|
|
|
@ -124,6 +128,7 @@ const transactionDataService = new (function TransactionDataService() {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const putTransactionsDirect = (txns, writeTransactionsById) => { |
|
|
|
|
console.log("putTransactionsDirect") |
|
|
|
|
return getSearchIndexForTransactions(txns).then(searchIndex => { |
|
|
|
|
txns.forEach( |
|
|
|
|
tx => searchTokenize(tx).forEach(token => { |
|
|
|
@ -157,6 +162,7 @@ const transactionDataService = new (function TransactionDataService() {
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
this.ingestTransactions = (txns) => { |
|
|
|
|
console.log("ingestTransactions") |
|
|
|
|
if(!Array.isArray(txns)) { |
|
|
|
|
txns = [txns]; |
|
|
|
|
} |
|
|
|
@ -193,6 +199,7 @@ const transactionDataService = new (function TransactionDataService() {
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
this.recreateSecondaryIndexes = () => { |
|
|
|
|
console.log("recreateSecondaryIndexes") |
|
|
|
|
return db.range({ |
|
|
|
|
gte: keyPrefixTxById, |
|
|
|
|
lte: keyPrefixTxById+'\xff' |
|
|
|
@ -202,6 +209,7 @@ const transactionDataService = new (function TransactionDataService() {
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
this.modifyTransactions = (txs) => { |
|
|
|
|
console.log("modifyTransactions") |
|
|
|
|
if(!Array.isArray(txs)) { |
|
|
|
|
txs = [txs]; |
|
|
|
|
} |
|
|
|
@ -268,6 +276,7 @@ const transactionDataService = new (function TransactionDataService() {
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
this.deleteTransactions = (txs, removeFromSearch) => { |
|
|
|
|
console.log("deleteTransactions") |
|
|
|
|
if(!Array.isArray(txs)) { |
|
|
|
|
txs = [txs]; |
|
|
|
|
} |
|
|
|
@ -304,6 +313,7 @@ const transactionDataService = new (function TransactionDataService() {
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
this.suggestToSlashFromForTransaction = (tx, categoriesAndAccounts) => { |
|
|
|
|
console.log("suggestToSlashFromForTransaction") |
|
|
|
|
//debugger;
|
|
|
|
|
const tokens = searchTokenize(tx); |
|
|
|
|
const popularities = {}; |
|
|
|
@ -343,6 +353,7 @@ const transactionDataService = new (function TransactionDataService() {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.getTransactionsByDateRange = (minMillisecondsSinceEpoch, maxMillisecondsSinceEpoch) => { |
|
|
|
|
console.log("getTransactionsByDateRange") |
|
|
|
|
return db.range({ |
|
|
|
|
gte: keyTxIdByDate(minMillisecondsSinceEpoch, 0), |
|
|
|
|
lte: keyTxIdByDate(maxMillisecondsSinceEpoch, 0) |
|
|
|
@ -350,10 +361,12 @@ const transactionDataService = new (function TransactionDataService() {
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
this.getTransactionsByAccountOrCategoryId = (accountOrCategoryId) => { |
|
|
|
|
console.log("getTransactionsByAccountOrCategoryId " + accountOrCategoryId) |
|
|
|
|
return db.keyPrefix(keyTxIdByAccountOrCategory(accountOrCategoryId)).then(getTransactionsByIdResults); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
this.getAllTransactions = () => { |
|
|
|
|
console.log("getAllTransactions ") |
|
|
|
|
return db.keyPrefix(keyPrefixTxById); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -376,7 +389,9 @@ const transactionDataService = new (function TransactionDataService() {
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
this.init = () => { |
|
|
|
|
console.log("tds init ") |
|
|
|
|
db.subscribeToOpen(() => { |
|
|
|
|
console.log("tds init subscribeToOpen") |
|
|
|
|
return Promise.all([ |
|
|
|
|
db.keyPrefix(keyPrefixAccounts), |
|
|
|
|
db.keyPrefix(keyPrefixCategories), |
|
|
|
@ -384,6 +399,7 @@ const transactionDataService = new (function TransactionDataService() {
|
|
|
|
|
db.get(keyMeta('randomColorId')).then(x => x, x => 0), |
|
|
|
|
db.get(keyMeta('accountOrCategoryId')).then(x => x, x => 0) |
|
|
|
|
]).then(results => { |
|
|
|
|
console.log("tds init subscribeToOpen 2") |
|
|
|
|
|
|
|
|
|
if(results[0].length) { |
|
|
|
|
navController.navigate('accounts'); |
|
|
|
@ -410,6 +426,7 @@ const transactionDataService = new (function TransactionDataService() {
|
|
|
|
|
db.keyPrefix(keyPrefixTxIdByDate), |
|
|
|
|
db.keyPrefix(keyPrefixTxById), |
|
|
|
|
]).then(results => { |
|
|
|
|
console.log("tds init subscribeToOpen 3") |
|
|
|
|
const constraintViolations = []; |
|
|
|
|
const accountByTxId = {}; |
|
|
|
|
const toSlashFromByTxId = {}; |
|
|
|
@ -494,6 +511,7 @@ const transactionDataService = new (function TransactionDataService() {
|
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
const onPutDelete = (operation, key, value) => { |
|
|
|
|
console.log("tds onPutDelete") |
|
|
|
|
if(operation == 'put') { |
|
|
|
|
accountsAndCategories[value.id] = value; |
|
|
|
|
} else if(operation == 'del') { |
|
|
|
|