Skip to content

Commit

Permalink
Merge pull request #121 from bitfinexcom/beta
Browse files Browse the repository at this point in the history
Update beta with master
  • Loading branch information
prdn authored Aug 18, 2020
2 parents 616b1dd + 8807b0d commit f048e24
Show file tree
Hide file tree
Showing 16 changed files with 360 additions and 149 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"lodash": "^4.17.11",
"moment": "^2.24.0",
"scrypt-js": "^3.0.0",
"sqlite3": "4.1.1",
"sqlite3": "5.0.0",
"uuid": "^8.0.0",
"yargs": "^13.2.4"
},
Expand Down
2 changes: 0 additions & 2 deletions worker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict'

process.versions.electron = process.env.ELECTRON_VERSION

module.exports = require('bfx-svc-boot-js')
4 changes: 2 additions & 2 deletions workers/loc.api/sync/currency.converter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ const {
FindMethodError
} = require('bfx-report/workers/loc.api/errors')
const {
getDataFromApi
getDataFromApi,
splitSymbolPairs
} = require('bfx-report/workers/loc.api/helpers')

const {
CurrencyConversionDataFindingError
} = require('../../errors')
const {
splitSymbolPairs,
isForexSymb
} = require('../helpers')
const { tryParseJSON } = require('../../helpers')
Expand Down
22 changes: 18 additions & 4 deletions workers/loc.api/sync/dao/dao.sqlite.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const {
} = require('inversify')
const {
getLimitNotMoreThan,
checkFilterParams
checkFilterParams,
normalizeFilterParams
} = require('bfx-report/workers/loc.api/helpers')
const {
AuthError
Expand Down Expand Up @@ -44,6 +45,12 @@ const {
} = require('../../errors')

class SqliteDAO extends DAO {
constructor (...args) {
super(...args)

this._transactionPromise = Promise.resolve()
}

_run (sql, params = []) {
return new Promise((resolve, reject) => {
this.db.run(sql, params, function (err) {
Expand Down Expand Up @@ -94,14 +101,16 @@ class SqliteDAO extends DAO {
return this._run('ROLLBACK')
}

_beginTrans (
async _beginTrans (
asyncExecQuery,
{
beforeTransFn,
afterTransFn
} = {}
) {
return new Promise((resolve, reject) => {
await this._transactionPromise

const promise = new Promise((resolve, reject) => {
this.db.serialize(async () => {
let isTransBegun = false

Expand Down Expand Up @@ -139,6 +148,10 @@ class SqliteDAO extends DAO {
}
})
})

this._transactionPromise = promise

return promise
}

async _createTablesIfNotExists () {
Expand Down Expand Up @@ -636,7 +649,7 @@ class SqliteDAO extends DAO {
*/
async findInCollBy (
method,
args,
reqArgs,
{
isPrepareResponse = false,
isPublic = false,
Expand All @@ -648,6 +661,7 @@ class SqliteDAO extends DAO {
) {
const filterModelName = filterModelNameMap.get(method)

const args = normalizeFilterParams(method, reqArgs)
checkFilterParams(filterModelName, args)

const { auth: user } = { ...args }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
'use strict'

const AbstractMigration = require('./abstract.migration')
const { getSqlArrToModifyColumns } = require('./helpers')

class MigrationV14 extends AbstractMigration {
/**
* @override
*/
up () {
const sqlArr = [
'ALTER TABLE ledgers ADD COLUMN _category INT',

/*
Delete all data from ledgers to allow
resync from scratch for adding categories
*/
'DELETE FROM ledgers'
]

this.addSql(sqlArr)
}

/**
* @override
*/
beforeDown () { return this.dao.disableForeignKeys() }

/**
* @override
*/
down () {
const sqlArr = [
...getSqlArrToModifyColumns(
'ledgers',
{
_id: 'INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT',
id: 'BIGINT',
currency: 'VARCHAR(255)',
mts: 'BIGINT',
amount: 'DECIMAL(22,12)',
amountUsd: 'DECIMAL(22,12)',
balance: 'DECIMAL(22,12)',
_nativeBalance: 'DECIMAL(22,12)',
balanceUsd: 'DECIMAL(22,12)',
_nativeBalanceUsd: 'DECIMAL(22,12)',
description: 'TEXT',
wallet: 'VARCHAR(255)',
_isMarginFundingPayment: 'INT',
_isAffiliateRebate: 'INT',
_isStakingPayments: 'INT',
_isBalanceRecalced: 'INT',
subUserId: 'INT',
user_id: 'INT NOT NULL',
__constraints__: `CONSTRAINT #{tableName}_fk_user_id
FOREIGN KEY (user_id)
REFERENCES users(_id)
ON UPDATE CASCADE
ON DELETE CASCADE`
}
)
]

this.addSql(sqlArr)
}

/**
* @override
*/
afterDown () { return this.dao.enableForeignKeys() }
}

module.exports = MigrationV14
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,20 @@ const getFieldsFilters = (
const field = _params[fieldName]

if (
typeof field === 'boolean' &&
Object.keys(model)
.some(key => key === modelFieldName)
) {
return {
...accum,
[modelFieldName]: Number(field)
if (typeof field === 'boolean') {
return {
...accum,
[modelFieldName]: Number(field)
}
}
if (typeof field === 'number') {
return {
...accum,
[modelFieldName]: field
}
}
}

Expand Down Expand Up @@ -59,7 +66,8 @@ module.exports = (
[
'isMarginFundingPayment',
'isAffiliateRebate',
'isStakingPayments'
'isStakingPayments',
'category'
],
params,
model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const TYPES = require('../../../di/types')
const SYNC_API_METHODS = require('../../schema/sync.api.methods')
const {
addPropsToResIfExist,
getFlagsFromLedgerDescription
getFlagsFromLedgerDescription,
getCategoryFromDescription
} = require('./helpers')

class ApiMiddlewareHandlerAfter {
Expand Down Expand Up @@ -124,6 +125,10 @@ class ApiMiddlewareHandlerAfter {
{
fieldName: '_isStakingPayments',
pattern: 'Staking Payments'
},
{
fieldName: '_category',
handler: getCategoryFromDescription
}
]
),
Expand Down
Loading

0 comments on commit f048e24

Please sign in to comment.