0
Fork 0
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:
Fabien 'egg' O'Carroll 2021-07-15 15:17:51 +01:00 committed by GitHub
parent 20aea8c819
commit 71ba9f3d17
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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