diff --git a/Dockerfile b/Dockerfile index a8a2dfd..adc4058 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,8 @@ -FROM node as build +FROM node:10 as build WORKDIR /app COPY . . -RUN yarn install +RUN yarn install --production=true -FROM node:latest +FROM node:10 COPY --from=build /app / -CMD ["node", "index.js"] \ No newline at end of file +CMD ["yarn", "trader"] \ No newline at end of file diff --git a/libs/actions.js b/libs/actions.js index 32038a6..4e6d06f 100644 --- a/libs/actions.js +++ b/libs/actions.js @@ -22,6 +22,7 @@ module.exports = ({ return memo } catch (e) { console.error('Failed to mergeTraderStats:', r.id, e.message) + memo.push(r) return memo } }, []) @@ -108,6 +109,16 @@ module.exports = ({ return events.listUserSorted(provider.id) }, + async listMyProviderTrades({ token, providerid }) { + assert(token, 'token required') + const { valid, userid, type } = await tokens.get(token) + assert(valid, 'token is no longer valid') + + const provider = await users.get(providerid) + assert(provider.userid === userid, 'provider does not belong to you.') + + return trades.listUserSorted(provider.id) + }, async listMyProviderStats({ token }) { assert(token, 'token required') const { valid, userid, type } = await tokens.get(token) diff --git a/libs/utils.js b/libs/utils.js index efbabdd..dd56fb2 100644 --- a/libs/utils.js +++ b/libs/utils.js @@ -16,9 +16,10 @@ exports.isEnvArray = (value = '') => { return value.toString().includes(',') } -const isLower = new RegExp('^[a-z0-9]') -exports.isEnvParsable = key => { - return isLower.test(key) +const isLower = '^[a-z0-9]' + +exports.IsEnvParsable = regex => key => { + return regex.test(key) } exports.parseEnvArray = value => { @@ -28,6 +29,10 @@ exports.parseEnvArray = value => { .value() } +exports.MapKey = regex => key => { + return key.replace(regex,'') +} + exports.mapValues = (kv, valueFn) => { return lodash.reduce( kv, @@ -39,11 +44,13 @@ exports.mapValues = (kv, valueFn) => { ) } -exports.parseEnv = env => { +exports.parseEnv = (env,regex=isLower) => { + regex = new RegExp(regex) + const isEnvParsable = exports.IsEnvParsable(regex) return lodash.reduce( env, (result, value, key) => { - if (!exports.isEnvParsable(key)) return result + if (!isEnvParsable(key)) return result const path = key.split('.') let val = value if (exports.isEnvArray(value)) { @@ -56,6 +63,18 @@ exports.parseEnv = env => { ) } +exports.mapValues = (kv, valueFn) => { + return lodash.reduce( + kv, + (result, value, key) => { + result[key] = valueFn(value) + return result + }, + {} + ) +} + + // TIME SHIT FOR STATS exports.defaultHourly = function(stats) {