mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 17:45:40 -05:00
Merge branch 'master' into production
This commit is contained in:
commit
1c53b1b9df
7 changed files with 24 additions and 5 deletions
|
@ -5,6 +5,10 @@
|
|||
|
||||
.code-input
|
||||
width: 100%
|
||||
|
||||
.course-image
|
||||
width: 100%
|
||||
|
||||
.course-panel
|
||||
margin: 20px
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ block content
|
|||
div.description 30 Day Total Growth
|
||||
div.count #{monthlyGrowth.toFixed(1)}%
|
||||
.col-md-5.big-stat.churn-count
|
||||
div.description Monthly Churn (cancelled / total)
|
||||
div.description 30 Day Churn (cancelled / total)
|
||||
div.count #{monthlyChurn.toFixed(1)}%
|
||||
|
||||
each graph in analytics.graphs
|
||||
|
|
|
@ -95,6 +95,10 @@ mixin course-block(course, courseID)
|
|||
strong #{course.unlocked ? '[ enrolled ]' : ''}
|
||||
.panel-body
|
||||
.container-fluid
|
||||
.row
|
||||
.col-md-12
|
||||
p
|
||||
img.course-image(src="#{course.image}")
|
||||
.row.button-row
|
||||
.col-md-6
|
||||
strong Topics
|
||||
|
|
|
@ -33,7 +33,6 @@ module.exports = class AnalyticsSubscriptionsView extends RootView
|
|||
context.subscriberCancelled = _.find context.subscribers, (subscriber) -> subscriber.cancel
|
||||
context.subscriberSponsored = _.find context.subscribers, (subscriber) -> subscriber.user?.stripe?.sponsorID
|
||||
context.total = @total ? 0
|
||||
context.cancelled = @cancellations?.length ? @cancelled ? 0
|
||||
context.monthlyChurn = @monthlyChurn ? 0.0
|
||||
context.monthlyGrowth = @monthlyGrowth ? 0.0
|
||||
context.outstandingCancels = @outstandingCancels ? []
|
||||
|
@ -52,7 +51,6 @@ module.exports = class AnalyticsSubscriptionsView extends RootView
|
|||
@analytics = graphs: []
|
||||
@subs = []
|
||||
@total = 0
|
||||
@cancelled = 0
|
||||
@monthlyChurn = 0.0
|
||||
@monthlyGrowth = 0.0
|
||||
@refreshDataState = 'Fetching dashboard data...'
|
||||
|
@ -258,14 +256,15 @@ module.exports = class AnalyticsSubscriptionsView extends RootView
|
|||
ended: subDayMap[day]['end'] or 0
|
||||
|
||||
@subs.sort (a, b) -> a.day.localeCompare(b.day)
|
||||
cancelledThisMonth = 0
|
||||
totalLastMonth = 0
|
||||
for sub, i in @subs
|
||||
@total += sub.started
|
||||
@total -= sub.ended
|
||||
@cancelled += sub.cancelled
|
||||
sub.total = @total
|
||||
cancelledThisMonth += sub.cancelled if @subs.length - i < 31
|
||||
totalLastMonth = @total if @subs.length - i is 31
|
||||
@monthlyChurn = @cancelled / totalLastMonth * 100.0 if totalLastMonth > 0
|
||||
@monthlyChurn = cancelledThisMonth / totalLastMonth * 100.0 if totalLastMonth > 0
|
||||
if @subs.length > 30 and @subs[@subs.length - 31].total > 0
|
||||
startMonthTotal = @subs[@subs.length - 31].total
|
||||
endMonthTotal = @subs[@subs.length - 1].total
|
||||
|
|
|
@ -28,6 +28,7 @@ module.exports =
|
|||
service: 'stripe'
|
||||
amount: parseInt(stripeCharge.amount)
|
||||
payment.set 'description', stripeCharge.metadata.description if stripeCharge.metadata.description
|
||||
payment.set 'gems', parseInt(stripeCharge.metadata.gems) if stripeCharge.metadata.gems
|
||||
payment.set 'stripe',
|
||||
customerID: stripeCharge.customer
|
||||
timestamp: parseInt(stripeCharge.metadata.timestamp)
|
||||
|
|
|
@ -127,6 +127,7 @@ class SubscriptionHandler extends Handler
|
|||
metadata =
|
||||
type: req.body.type
|
||||
userID: req.user._id + ''
|
||||
gems: subscriptions.basic.gems * 12
|
||||
timestamp: parseInt(req.body.stripe?.timestamp)
|
||||
description: req.body.description
|
||||
|
||||
|
@ -146,6 +147,14 @@ class SubscriptionHandler extends Handler
|
|||
stripeInfo = _.cloneDeep(req.user.get('stripe') ? {})
|
||||
stripeInfo.free = endDate.toISOString().substring(0, 10)
|
||||
req.user.set('stripe', stripeInfo)
|
||||
|
||||
# Add year's worth of gems to User
|
||||
purchased = _.clone(req.user.get('purchased'))
|
||||
purchased ?= {}
|
||||
purchased.gems ?= 0
|
||||
purchased.gems += parseInt(charge.metadata.gems)
|
||||
req.user.set('purchased', purchased)
|
||||
|
||||
req.user.save (err, user) =>
|
||||
if err
|
||||
@logSubscriptionError(req.user, "User save error: #{JSON.stringify(err)}")
|
||||
|
|
|
@ -1394,7 +1394,9 @@ describe 'Subscriptions', ->
|
|||
endDate.setUTCFullYear(endDate.getUTCFullYear() + 1)
|
||||
expect(stripeInfo.free).toEqual(endDate.toISOString().substring(0, 10))
|
||||
expect(stripeInfo.customerID).toBeDefined()
|
||||
expect(user1.get('purchased')?.gems).toEqual(3500*12)
|
||||
Payment.findOne 'stripe.customerID': stripeInfo.customerID, (err, payment) ->
|
||||
expect(err).toBeNull()
|
||||
expect(payment).toBeDefined()
|
||||
expect(payment.get('gems')).toEqual(3500*12)
|
||||
done()
|
||||
|
|
Loading…
Reference in a new issue