Skip to content

Commit

Permalink
fix(scripts/monthly/user-report): we should filter orders that either…
Browse files Browse the repository at this point in the history
… don't have subscription OR have active subscriptions, consider UsingVirtualCardFromCollectiveId as well
  • Loading branch information
marcogbarcellos committed Dec 3, 2018
1 parent a10577b commit 8b48432
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions cron/monthly/user-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ const processBacker = async FromCollectiveId => {
const query = {
attributes: ['CollectiveId', 'HostCollectiveId'],
where: {
FromCollectiveId,
[Op.or]: {
FromCollectiveId,
UsingVirtualCardFromCollectiveId: FromCollectiveId,
},
type: 'CREDIT',
createdAt: { [Op.gte]: startDate, [Op.lt]: endDate },
},
Expand Down Expand Up @@ -188,7 +191,7 @@ const processBacker = async FromCollectiveId => {
{ concurrency: 4 },
);
}
const orders = await models.Order.findAll({
let orders = await models.Order.findAll({
attributes: ['id', 'CollectiveId', 'totalAmount', 'currency'],
where: {
FromCollectiveId,
Expand All @@ -198,17 +201,10 @@ const processBacker = async FromCollectiveId => {
},
deletedAt: null,
},
include: [
{
model: models.Subscription,
where: {
isActive: true,
},
},
],
include: [{ model: models.Subscription }],
});

const ordersByCollectiveId = groupBy(orders, 'CollectiveId');
// group orders(by collective) that either don't have subscription or have active subscription
const ordersByCollectiveId = groupBy(orders.filter(o => !o.Subscription || o.Subscription.isActive), 'CollectiveId');
const collectivesWithOrders = [];
collectives.map(collective => {
// It's only possible to have one order with subscription active Per Collective
Expand Down

0 comments on commit 8b48432

Please sign in to comment.