Skip to content

Commit

Permalink
listMyProviderTrades
Browse files Browse the repository at this point in the history
  • Loading branch information
tacyarg committed Dec 2, 2019
1 parent 20a6d8a commit f96ad9c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
CMD ["yarn", "trader"]
11 changes: 11 additions & 0 deletions libs/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = ({
return memo
} catch (e) {
console.error('Failed to mergeTraderStats:', r.id, e.message)
memo.push(r)
return memo
}
}, [])
Expand Down Expand Up @@ -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)
Expand Down
29 changes: 24 additions & 5 deletions libs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -28,6 +29,10 @@ exports.parseEnvArray = value => {
.value()
}

exports.MapKey = regex => key => {
return key.replace(regex,'')
}

exports.mapValues = (kv, valueFn) => {
return lodash.reduce(
kv,
Expand All @@ -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)) {
Expand All @@ -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) {
Expand Down

0 comments on commit f96ad9c

Please sign in to comment.