Skip to content

Commit

Permalink
refactor(jobs): extract marketplace_purchase logic into a function
Browse files Browse the repository at this point in the history
  • Loading branch information
Realtin committed Oct 2, 2017
1 parent 199d587 commit 8c98d44
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion jobs/github-event/marketplace_purchase/changed.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const dbs = require('../../../lib/dbs')
const upsert = require('../../../lib/upsert')
const normalizePlanName = require('../../../lib/normalize-plan-name')

module.exports = async function ({ marketplace_purchase }) {
const { payments } = await dbs()
const accountId = String(marketplace_purchase.account.id)

await upsert(payments, accountId, {
plan: marketplace_purchase.plan.name.toLowerCase().replace(' ', '')
plan: normalizePlanName(marketplace_purchase.plan.name)
})
}
3 changes: 2 additions & 1 deletion jobs/github-event/marketplace_purchase/purchased.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const dbs = require('../../../lib/dbs')
const upsert = require('../../../lib/upsert')
const normalizePlanName = require('../../../lib/normalize-plan-name')

module.exports = async function ({ marketplace_purchase }) {
const { payments } = await dbs()
Expand All @@ -8,7 +9,7 @@ module.exports = async function ({ marketplace_purchase }) {
let paymentDoc

await upsert(payments, accountId, {
plan: marketplace_purchase.plan.name.toLowerCase().replace(' ', '')
plan: normalizePlanName(marketplace_purchase.plan.name)
})

try {
Expand Down
3 changes: 3 additions & 0 deletions lib/normalize-plan-name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function normalizePlanName (planName) {
return planName.toLowerCase().replace(' ', '')
}

0 comments on commit 8c98d44

Please sign in to comment.