这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion test/5-queue-load.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@ describe('Queue load', () => {

mockRESTv2Srv = createMockRESTv2SrvWithDate(start, end, null, {
ledgers: { limit },
user_info: null
user_info: null,
symbols: null,
map_symbols: null,
inactive_currencies: null,
margin_currencies: null,
inactive_symbols: null,
futures: null,
currencies: null
})

await rmAllFiles(tempDirPath)
Expand Down
3 changes: 2 additions & 1 deletion workers/loc.api/generate-report-file/report.file.job.data.js
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,8 @@ class ReportFileJobData {
note: 'NOTE'
},
formatSettings: {
mtsUpdated: 'date'
mtsUpdated: 'date',
currency: 'prepareCurrency'
}
}

Expand Down
35 changes: 33 additions & 2 deletions workers/loc.api/queue/write-data-to-stream/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,32 @@ const _validTxtTimeZone = (val, timezone, format) => {
}

const _formatters = {
prepareCurrency: (ccy, params) => {
const currencyName = params?.allDataFields?.currencyName
const currencyNameMap = params?.symbols?.currencyNameMap

if (
!ccy ||
typeof ccy !== 'string' ||
!currencyName ||
typeof currencyName !== 'string' ||
!currencyNameMap ||
typeof currencyNameMap !== 'object'
) {
return ccy
}
if (
ccy !== 'USDt' &&
ccy !== 'UST'
) {
return ccy
}

const ccyId = currencyName.replace('TETHER', '')
const name = currencyNameMap[ccyId]

return name ?? ccy
},
date: (
val,
{
Expand Down Expand Up @@ -112,22 +138,27 @@ const _dataFormatter = (data, formatSettings, params) => {
const objArr = isArray ? clonedData : [clonedData]

for (const obj of objArr) {
const formatterParams = {
...params,
allDataFields: obj
}

for (const [key, val] of Object.entries(formatSettings)) {
try {
if (
typeof obj[key] !== 'undefined' &&
val &&
typeof val === 'object'
) {
obj[key] = _dataFormatter(obj[key], val, params)
obj[key] = _dataFormatter(obj[key], val, formatterParams)

continue
}
if (
typeof obj[key] !== 'undefined' &&
typeof _formatters[val] === 'function'
) {
obj[key] = _formatters[val](obj[key], params)
obj[key] = _formatters[val](obj[key], formatterParams)

continue
}
Expand Down
16 changes: 14 additions & 2 deletions workers/loc.api/queue/write-data-to-stream/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ module.exports = (
const currIterationArgs = cloneDeep(_args)

const getData = rService[method].bind(rService)
const getSymbols = rService.getSymbols.bind(rService)
const symbols = (await getDataFromApi({
getData: getSymbols,
args: {},
callerName: 'REPORT_FILE_WRITER',
shouldNotInterrupt: true
})) ?? {}
symbols.currencyNameMap = symbols.currencies.reduce((accum, curr) => {
accum[curr?.id] = curr?.name

return accum
}, {})

let count = 0
let serialRequestsCount = 0
Expand Down Expand Up @@ -101,7 +113,7 @@ module.exports = (
res,
stream,
formatSettings,
{ ..._args.params },
{ ..._args.params, symbols },
method
)
processorQueue.emit('progress', 100)
Expand Down Expand Up @@ -142,7 +154,7 @@ module.exports = (
res,
stream,
formatSettings,
{ ..._args.params },
{ ..._args.params, symbols },
method
)

Expand Down