mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Readded support for comped status in event aggregate (#13142)
refs https://github.com/TryGhost/Team/issues/880 The aggregate for `paid_delta` was incorrect as it did not handle the case where an event went from paid->comped or from comped->paid. This resulted in an overcount for paid members.
This commit is contained in:
parent
20aea8c819
commit
71ba9f3d17
1 changed files with 8 additions and 5 deletions
|
@ -17,12 +17,15 @@ const MemberStatusEvent = ghostBookshelf.Model.extend({
|
|||
return qb.clear('select')
|
||||
.select(knex.raw('DATE(created_at) as date'))
|
||||
.select(knex.raw(`SUM(
|
||||
CASE WHEN to_status IN ('paid', 'comped') THEN 1
|
||||
WHEN from_status IN ('paid', 'comped') THEN -1
|
||||
ELSE 0
|
||||
END
|
||||
CASE WHEN to_status='paid' THEN 1
|
||||
WHEN from_status='paid' THEN -1
|
||||
ELSE 0 END
|
||||
) as paid_delta`))
|
||||
.select(knex.raw(`0 as comped_delta`))
|
||||
.select(knex.raw(`SUM(
|
||||
CASE WHEN to_status='comped' THEN 1
|
||||
WHEN from_status='comped' THEN -1
|
||||
ELSE 0 END
|
||||
) as comped_delta`))
|
||||
.select(knex.raw(`SUM(
|
||||
CASE WHEN to_status='free' THEN 1
|
||||
WHEN from_status='free' THEN -1
|
||||
|
|
Loading…
Add table
Reference in a new issue