-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #380 from ZIMkaRU/feature/add-transaction-tax-repo…
…rt-v2 [PART-1] Add transaction tax report
- Loading branch information
Showing
11 changed files
with
246 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict' | ||
|
||
const TRX_TAX_STRATEGIES = require('./trx.tax.strategies') | ||
|
||
module.exports = { | ||
TRX_TAX_STRATEGIES | ||
} |
8 changes: 8 additions & 0 deletions
8
workers/loc.api/sync/transaction.tax.report/helpers/trx.tax.strategies.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict' | ||
|
||
const TRX_TAX_STRATEGIES = { | ||
FIFO: 'FIFO', | ||
LIFO: 'LIFO' | ||
} | ||
|
||
module.exports = TRX_TAX_STRATEGIES |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
'use strict' | ||
|
||
const { | ||
TRX_TAX_STRATEGIES | ||
} = require('./helpers') | ||
|
||
const { decorateInjectable } = require('../../di/utils') | ||
|
||
const depsTypes = (TYPES) => [ | ||
TYPES.DAO, | ||
TYPES.Authenticator, | ||
TYPES.SyncSchema, | ||
TYPES.ALLOWED_COLLS, | ||
TYPES.SYNC_API_METHODS, | ||
TYPES.Movements, | ||
TYPES.RService, | ||
TYPES.GetDataFromApi, | ||
TYPES.WSEventEmitterFactory, | ||
TYPES.Logger | ||
] | ||
class TransactionTaxReport { | ||
constructor ( | ||
dao, | ||
authenticator, | ||
syncSchema, | ||
ALLOWED_COLLS, | ||
SYNC_API_METHODS, | ||
movements, | ||
rService, | ||
getDataFromApi, | ||
wsEventEmitterFactory, | ||
logger | ||
) { | ||
this.dao = dao | ||
this.authenticator = authenticator | ||
this.syncSchema = syncSchema | ||
this.ALLOWED_COLLS = ALLOWED_COLLS | ||
this.SYNC_API_METHODS = SYNC_API_METHODS | ||
this.movements = movements | ||
this.rService = rService | ||
this.getDataFromApi = getDataFromApi | ||
this.wsEventEmitterFactory = wsEventEmitterFactory | ||
this.logger = logger | ||
|
||
this.tradesModel = this.syncSchema.getModelsMap() | ||
.get(this.ALLOWED_COLLS.TRADES) | ||
} | ||
|
||
async makeTrxTaxReportInBackground (args = {}) { | ||
const { auth, params } = args ?? {} | ||
const user = await this.authenticator | ||
.verifyRequestUser({ auth }) | ||
const _args = { auth: user, params } | ||
|
||
this.wsEventEmitterFactory() | ||
.emitTrxTaxReportGenerationInBackgroundToOne(() => { | ||
return this.getTransactionTaxReport(_args) | ||
}, user) | ||
.then(() => {}, (err) => { | ||
this.logger.error(`TRX_TAX_REPORT_GEN_FAILED: ${err.stack || err}`) | ||
}) | ||
|
||
return true | ||
} | ||
|
||
async getTransactionTaxReport (args = {}) { | ||
const { auth, params } = args ?? {} | ||
const start = params.start ?? 0 | ||
const end = params.end ?? Date.now() | ||
const strategy = params.strategy ?? TRX_TAX_STRATEGIES.LIFO | ||
const user = await this.authenticator | ||
.verifyRequestUser({ auth }) | ||
|
||
const isFIFO = strategy === TRX_TAX_STRATEGIES.FIFO | ||
const isLIFO = strategy === TRX_TAX_STRATEGIES.LIFO | ||
|
||
// TODO: | ||
return [] | ||
} | ||
} | ||
|
||
decorateInjectable(TransactionTaxReport, depsTypes) | ||
|
||
module.exports = TransactionTaxReport |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters