Skip to content
This repository has been archived by the owner on Jul 9, 2019. It is now read-only.

Commit

Permalink
switch out giving query and handle graceful fallbacks for studies con… (
Browse files Browse the repository at this point in the history
#1693)

* switch out giving query and handle graceful fallbacks for studies content

* fix lint error
  • Loading branch information
James Baxley authored Jan 1, 2017
1 parent 15d4065 commit 05189c4
Show file tree
Hide file tree
Showing 6 changed files with 288 additions and 66 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
exports[`data format should return an object with correct keys 1`] = `
Object {
"accounts": Object {
"Christmas Offering": 0,
"General Fund": 66,
"Step Up Fund": 0,
},
"chartData": Array [
Object {
Expand Down Expand Up @@ -68,5 +66,199 @@ Object {
},
],
"total": 66,
"transactions": Array [
Object {
"date": "Tue Nov 01 2016 07:53:00 GMT-0400 (EDT)",
"details": Array [
Object {
"account": Object {
"name": "General Fund",
},
"amount": 1,
},
],
"id": "123456781",
},
Object {
"date": "Mon Oct 03 2016 07:55:09 GMT-0400 (EDT)",
"details": Array [
Object {
"account": Object {
"name": "General Fund",
},
"amount": 2,
},
],
"id": "123456782",
},
Object {
"date": "Thu Sep 01 2016 09:41:39 GMT-0400 (EDT)",
"details": Array [
Object {
"account": Object {
"name": "General Fund",
},
"amount": 3,
},
],
"id": "123456783",
},
Object {
"date": "Mon Aug 01 2016 13:13:31 GMT-0400 (EDT)",
"details": Array [
Object {
"account": Object {
"name": "General Fund",
},
"amount": 4,
},
],
"id": "123456784",
},
Object {
"date": "Fri Jul 01 2016 10:26:52 GMT-0400 (EDT)",
"details": Array [
Object {
"account": Object {
"name": "General Fund",
},
"amount": 5,
},
],
"id": "123456785",
},
Object {
"date": "Wed Jun 01 2016 07:51:23 GMT-0400 (EDT)",
"details": Array [
Object {
"account": Object {
"name": "General Fund",
},
"amount": 6,
},
],
"id": "123456786",
},
Object {
"date": "Fri May 13 2016 15:08:35 GMT-0400 (EDT)",
"details": Array [
Object {
"account": Object {
"name": "General Fund",
},
"amount": 7,
},
],
"id": "123456787",
},
Object {
"date": "Sat Apr 30 2016 09:50:11 GMT-0400 (EDT)",
"details": Array [
Object {
"account": Object {
"name": "General Fund",
},
"amount": 8,
},
],
"id": "12345678",
},
Object {
"date": "Sat Apr 30 2016 09:49:35 GMT-0400 (EDT)",
"details": Array [
Object {
"account": Object {
"name": "General Fund",
},
"amount": 9,
},
],
"id": "12345678",
},
Object {
"date": "Mon Apr 18 2016 15:42:15 GMT-0400 (EDT)",
"details": Array [
Object {
"account": Object {
"name": "General Fund",
},
"amount": 0,
},
],
"id": "12345678",
},
Object {
"date": "Fri Apr 01 2016 11:12:21 GMT-0400 (EDT)",
"details": Array [
Object {
"account": Object {
"name": "General Fund",
},
"amount": 1,
},
],
"id": "12345678",
},
Object {
"date": "Thu Mar 31 2016 09:30:01 GMT-0400 (EDT)",
"details": Array [
Object {
"account": Object {
"name": "General Fund",
},
"amount": 2,
},
],
"id": "12345678",
},
Object {
"date": "Thu Mar 03 2016 02:42:37 GMT-0500 (EST)",
"details": Array [
Object {
"account": Object {
"name": "General Fund",
},
"amount": 3,
},
],
"id": "12345678",
},
Object {
"date": "Tue Mar 01 2016 06:20:39 GMT-0500 (EST)",
"details": Array [
Object {
"account": Object {
"name": "General Fund",
},
"amount": 4,
},
],
"id": "12345678",
},
Object {
"date": "Sat Jan 30 2016 07:37:32 GMT-0500 (EST)",
"details": Array [
Object {
"account": Object {
"name": "General Fund",
},
"amount": 5,
},
],
"id": "12345678",
},
Object {
"date": "Fri Jan 01 2016 15:47:43 GMT-0500 (EST)",
"details": Array [
Object {
"account": Object {
"name": "General Fund",
},
"amount": 6,
},
],
"id": "12345678",
},
],
}
`;
75 changes: 34 additions & 41 deletions imports/pages/give/home/__tests__/givingSummaryEnhancer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,40 @@ import {formatGivingSummaryData} from "../givingSummaryEnhancer";

const mockGQLData = {
"data": {
"accounts": [
{
"total": 66, "name": "General Fund",
"transactions": [
{"id": "123456781", "date": "Tue Nov 01 2016 07:53:00 GMT-0400 (EDT)",
"details": [{ "amount": 1 }]},
{"id": "123456782", "date": "Mon Oct 03 2016 07:55:09 GMT-0400 (EDT)",
"details": [{ "amount": 2 }]},
{"id": "123456783", "date": "Thu Sep 01 2016 09:41:39 GMT-0400 (EDT)",
"details": [{ "amount": 3 }]},
{"id": "123456784", "date": "Mon Aug 01 2016 13:13:31 GMT-0400 (EDT)",
"details": [{ "amount": 4 }]},
{"id": "123456785", "date": "Fri Jul 01 2016 10:26:52 GMT-0400 (EDT)",
"details": [{ "amount": 5 }]},
{"id": "123456786", "date": "Wed Jun 01 2016 07:51:23 GMT-0400 (EDT)",
"details": [{ "amount": 6 }]},
{"id": "123456787", "date": "Fri May 13 2016 15:08:35 GMT-0400 (EDT)",
"details": [{ "amount": 7 }]},
{"id": "12345678", "date": "Sat Apr 30 2016 09:50:11 GMT-0400 (EDT)",
"details": [{ "amount": 8 }]},
{"id": "12345678", "date": "Sat Apr 30 2016 09:49:35 GMT-0400 (EDT)",
"details": [{ "amount": 9 }]},
{"id": "12345678", "date": "Mon Apr 18 2016 15:42:15 GMT-0400 (EDT)",
"details": [{ "amount": 0 }]},
{"id": "12345678", "date": "Fri Apr 01 2016 11:12:21 GMT-0400 (EDT)",
"details": [{ "amount": 1 }]},
{"id": "12345678", "date": "Thu Mar 31 2016 09:30:01 GMT-0400 (EDT)",
"details": [{ "amount": 2 }]},
{"id": "12345678", "date": "Thu Mar 03 2016 02:42:37 GMT-0500 (EST)",
"details": [{ "amount": 3 }]},
{"id": "12345678", "date": "Tue Mar 01 2016 06:20:39 GMT-0500 (EST)",
"details": [{ "amount": 4 }]},
{"id": "12345678", "date": "Sat Jan 30 2016 07:37:32 GMT-0500 (EST)",
"details": [{ "amount": 5 }]},
{"id": "12345678", "date": "Fri Jan 01 2016 15:47:43 GMT-0500 (EST)",
"details": [{ "amount": 6 }] }
],
},
{ "total": 0, "name": "Christmas Offering", "transactions": []},
{ "total": 0, "name": "Step Up Fund", "transactions": []}
]
"transactions": [
{"id": "123456781", "date": "Tue Nov 01 2016 07:53:00 GMT-0400 (EDT)",
"details": [{ "account": { "name": "General Fund"}, "amount": 1 }]},
{"id": "123456782", "date": "Mon Oct 03 2016 07:55:09 GMT-0400 (EDT)",
"details": [{ "account": { "name": "General Fund"}, "amount": 2 }]},
{"id": "123456783", "date": "Thu Sep 01 2016 09:41:39 GMT-0400 (EDT)",
"details": [{ "account": { "name": "General Fund"}, "amount": 3 }]},
{"id": "123456784", "date": "Mon Aug 01 2016 13:13:31 GMT-0400 (EDT)",
"details": [{ "account": { "name": "General Fund"}, "amount": 4 }]},
{"id": "123456785", "date": "Fri Jul 01 2016 10:26:52 GMT-0400 (EDT)",
"details": [{ "account": { "name": "General Fund"}, "amount": 5 }]},
{"id": "123456786", "date": "Wed Jun 01 2016 07:51:23 GMT-0400 (EDT)",
"details": [{ "account": { "name": "General Fund"}, "amount": 6 }]},
{"id": "123456787", "date": "Fri May 13 2016 15:08:35 GMT-0400 (EDT)",
"details": [{ "account": { "name": "General Fund"}, "amount": 7 }]},
{"id": "12345678", "date": "Sat Apr 30 2016 09:50:11 GMT-0400 (EDT)",
"details": [{ "account": { "name": "General Fund"}, "amount": 8 }]},
{"id": "12345678", "date": "Sat Apr 30 2016 09:49:35 GMT-0400 (EDT)",
"details": [{ "account": { "name": "General Fund"}, "amount": 9 }]},
{"id": "12345678", "date": "Mon Apr 18 2016 15:42:15 GMT-0400 (EDT)",
"details": [{ "account": { "name": "General Fund"}, "amount": 0 }]},
{"id": "12345678", "date": "Fri Apr 01 2016 11:12:21 GMT-0400 (EDT)",
"details": [{ "account": { "name": "General Fund"}, "amount": 1 }]},
{"id": "12345678", "date": "Thu Mar 31 2016 09:30:01 GMT-0400 (EDT)",
"details": [{ "account": { "name": "General Fund"}, "amount": 2 }]},
{"id": "12345678", "date": "Thu Mar 03 2016 02:42:37 GMT-0500 (EST)",
"details": [{ "account": { "name": "General Fund"}, "amount": 3 }]},
{"id": "12345678", "date": "Tue Mar 01 2016 06:20:39 GMT-0500 (EST)",
"details": [{ "account": { "name": "General Fund"}, "amount": 4 }]},
{"id": "12345678", "date": "Sat Jan 30 2016 07:37:32 GMT-0500 (EST)",
"details": [{ "account": { "name": "General Fund"}, "amount": 5 }]},
{"id": "12345678", "date": "Fri Jan 01 2016 15:47:43 GMT-0500 (EST)",
"details": [{ "account": { "name": "General Fund"}, "amount": 6 }] }
],
}
}

Expand Down
46 changes: 23 additions & 23 deletions imports/pages/give/home/givingSummaryEnhancer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,30 @@ export const formatGivingSummaryData = (data: Object): ?Object => {
{ month: "December", amount: 0, tick: "D" },
];

if (!data || !data.accounts) return null;
const accountsData = data.accounts;
if (!data || !data.transactions) return null;
const transactions = data.transactions;

if (!Array.isArray(accountsData)) return null;
if (!Array.isArray(transactions)) return null;
const summaryData = [...baseData];

let total = 0;
const accounts = {};

accountsData.map((account) => {
accounts[account.name] = account.total;
if (!account.transactions) return null;

transactions.map((transaction) => {
// iterate over every transaction, and sum up the months
account.transactions.map((transaction) => {
const month = moment(new Date(transaction.date)).format("M");
if (!transaction.details || !transaction.details.length) return transaction;
summaryData[Number(month) - 1].amount += transaction.details
.reduce((prev, { amount }) => prev + amount, 0);
total += transaction.details.reduce((prev, { amount }) => prev + amount, 0);
return transaction;
const month = moment(new Date(transaction.date)).format("M");
if (!transaction.details || !transaction.details.length) return transaction;

summaryData[Number(month) - 1].amount += transaction.details
.reduce((prev, { amount }) => prev + amount, 0);

total += transaction.details.reduce((prev, { amount }) => prev + amount, 0);
transaction.details.forEach(({ amount, account }) => {
if (!account) return;
if (!accounts[account.name]) accounts[account.name] = 0;
accounts[account.name] += amount;
});
return null;
return transaction;
});

return ({
Expand All @@ -58,14 +59,13 @@ export const formatGivingSummaryData = (data: Object): ?Object => {

const YTD_QUERY = gql`
query givingSummary($start: String!, $end: String!) {
accounts(allFunds: true) {
total(start: $start, end: $end)
name
transactions(limit: 0, start: $start, end: $end) {
id
date
details {
amount
transactions(start: $start, end: $end, limit: 0) {
id
date
details {
amount
account {
name
}
}
}
Expand Down
Loading

0 comments on commit 05189c4

Please sign in to comment.