Skip to content

Commit

Permalink
Merge pull request #1037 from knod/code-style-14
Browse files Browse the repository at this point in the history
Cleans '/src/utils' through 'interpolation.js'. #1018. Also #708.
  • Loading branch information
knod committed Dec 12, 2018
2 parents 46f6195 + 0278512 commit e4d5566
Show file tree
Hide file tree
Showing 11 changed files with 200 additions and 186 deletions.
116 changes: 58 additions & 58 deletions src/utils/CLIENT_DEFAULTS.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,79 +6,79 @@ import { cloneDeep } from 'lodash';
*
* Note: A 'positive number' money value can have more than
* two decimal places.
*
* @namespace
*/
const CLIENT_DEFAULTS = {

// Property Name | Default Value | Valid Value Description

// @todo get this value from the app somewhere
USState: 'MA', // Two-letter code denoting the state the client is in
// @todo get this value from the app somewhere
USState: `MA`, // Two-letter code denoting the state the client is in

current: {
// Current programs
benefits: [], // Benefit names (e.g. 'snap', 'section8')
benefits: [], // Benefit names (e.g. 'snap', 'section8')
// Household
// 'm_' for 'member'
household: [
{ // 'head' member // one or more member objects
m_age: 30, // whole number
m_role: 'head', // 'head', 'spouse', 'member'
m_disabled: false, // boolean
household: [ // one or more member objects. 'm_' for 'member'
{
m_age: 30, // whole number
m_role: `head`, // 'head', 'spouse', 'member'
m_disabled: false, // boolean
},
],

// Income
earned: 0, // positive number (can have more than two decimal places)
TAFDC: 0, // positive number
SSI: 0, // positive number
SSDI: 0, // positive number
childSupportIn: 0, // positive number
unemployment: 0, // positive number
workersComp: 0, // positive number
pension: 0, // positive number
socialSecurity: 0, // positive number
alimony: 0, // positive number
otherIncome: 0, // positive number
earned: 0, // positive number (can have more than two decimal places)
TAFDC: 0, // positive number
SSI: 0, // positive number
SSDI: 0, // positive number
childSupportIn: 0, // positive number
unemployment: 0, // positive number
workersComp: 0, // positive number
pension: 0, // positive number
socialSecurity: 0, // positive number
alimony: 0, // positive number
otherIncome: 0, // positive number
// Expenses
childDirectCare: 0, // positive number
childBeforeAndAfterSchoolCare: 0, // positive number
childTransportation: 0, // positive number
childOtherCare: 0, // positive number
earnedBecauseOfChildCare: 0, // positive number
childSupportPaidOut: 0, // positive number
adultDirectCare: 0, // positive number
adultTransportation: 0, // positive number
adultOtherCare: 0, // positive number
disabledAssistance: 0, // positive number
earnedBecauseOfAdultCare: 0, // positive number
disabledMedical: 0, // positive number
otherMedical: 0, // positive number
childDirectCare: 0, // positive number
childBeforeAndAfterSchoolCare: 0, // positive number
childTransportation: 0, // positive number
childOtherCare: 0, // positive number
earnedBecauseOfChildCare: 0, // positive number
childSupportPaidOut: 0, // positive number
adultDirectCare: 0, // positive number
adultTransportation: 0, // positive number
adultOtherCare: 0, // positive number
disabledAssistance: 0, // positive number
earnedBecauseOfAdultCare: 0, // positive number
disabledMedical: 0, // positive number
otherMedical: 0, // positive number
/** @todo Make housing expense values more robust. */
housing: 'homeless', // 'homeless', 'homeowner', 'renter', 'voucher'
contractRent: 0, // positive number
rentShare: 0, // positive number
rent: 0, // positive number
mortgage: 0, // positive number
housingInsurance: 0, // positive number
propertyTax: 0, // positive number
climateControl: false, // boolean
nonHeatElectricity: false, // boolean
phone: false, // boolean
fuelAssistance: false, // boolean Note: Input is 'yes', 'no', but should be being converted
otherExpensesFood: 0, // postitive number
otherExpensesUtilities: 0, // postitive number
otherExpensesCable: 0, // postitive number
otherExpensesMedical: 0, // postitive number
otherExpensesTransport: 0, // postitive number
otherExpensesCareProducts: 0, // postitive number
otherExpensesClothes: 0, // postitive number
otherExpensesPhone: 0, // postitive number
otherExpensesEntertainment: 0, // postitive number
otherExpensesOther: 0, // postitive number
wantsToSeeOtherExpenses: false, // boolean
housing: `homeless`, // 'homeless', 'homeowner', 'renter', 'voucher'
contractRent: 0, // positive number
rentShare: 0, // positive number
rent: 0, // positive number
mortgage: 0, // positive number
housingInsurance: 0, // positive number
propertyTax: 0, // positive number
climateControl: false, // boolean
nonHeatElectricity: false, // boolean
phone: false, // boolean
fuelAssistance: false, // boolean Note: Input is 'yes', 'no', but should be being converted
otherExpensesFood: 0, // postitive number
otherExpensesUtilities: 0, // postitive number
otherExpensesCable: 0, // postitive number
otherExpensesMedical: 0, // postitive number
otherExpensesTransport: 0, // postitive number
otherExpensesCareProducts: 0, // postitive number
otherExpensesClothes: 0, // postitive number
otherExpensesPhone: 0, // postitive number
otherExpensesEntertainment: 0, // postitive number
otherExpensesOther: 0, // postitive number
wantsToSeeOtherExpenses: false, // boolean
},

// Note: A `future` value will default to the client's `current` value until a user changes it explicitly
future: {}, // same structure // same
future: {}, // will be copy of `current`

};

Expand Down
24 changes: 12 additions & 12 deletions src/utils/cashflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
const getDependentCostsMonthly = function (client) {
let props = UNDER13_CARE_EXPENSES.concat(OVER12_CARE_EXPENSES);
return sumProps(client, props);
}; // End getDependentCostsMonthly()
};


/**
Expand All @@ -47,27 +47,27 @@ const getDependentCostsMonthly = function (client) {
*/
const getUnder13Expenses = function (client) {
return sumProps(client, UNDER13_CARE_EXPENSES);
}; // End getUnder13Expenses()
};


const getOver12Expenses = function (client) {
return sumProps(client, OVER12_CARE_EXPENSES);
}; // End getOver13Expenses()
};


const getMedicalExpenses = function (client) {
return sumProps(client, ALL_MEDICAL_EXPENSES);
}; // End getMedicalExpenses()
};


const getNonTransportCareCosts = function (client) {
return sumProps(client, NON_TRANSPORT_DEPENDENT_COSTS);
}; // End getNonTransportationCareCosts()
};


const getTransportDependentCosts = function (client) {
return sumProps(client, TRANSPORT_DEPENDENT_COSTS);
}; // End getTransportDependentCosts()
};


// ==================================
Expand All @@ -84,7 +84,7 @@ const getHousingCosts = function (client) {
} else if (housing === `homeowner`) {
return sumProps(client, HOMEOWNER_COSTS);
}
}; // End getHousingCosts()
};


// ==================================
Expand All @@ -101,7 +101,7 @@ const getHousingCosts = function (client) {
*/
const getGrossUnearnedIncomeMonthly = function (client) {
return sumProps(client, UNEARNED_INCOME_SOURCES);
}; // End getGrossUnearnedIncomeMonthly()
};


/**
Expand All @@ -115,10 +115,10 @@ const getGrossUnearnedIncomeMonthly = function (client) {
* income with no deductions or exclusions.
*/
const getSimpleGrossIncomeMonthly = function (client) {
let earned = client.earned,
unearned = getGrossUnearnedIncomeMonthly(client);
let earned = client.earned,
unearned = getGrossUnearnedIncomeMonthly(client);
return earned + unearned;
}; // End getSimpleGrossIncomeMonthly()
};


// ==================================
Expand All @@ -136,7 +136,7 @@ const getSimpleGrossIncomeMonthly = function (client) {
*/
const sumProps = function (obj, props) {
return sum(values(pick(obj, props)));
}; // End sumProps()
};


export {
Expand Down
42 changes: 21 additions & 21 deletions src/utils/convert-by-timescale.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ let toYearlyFrom = function (amount, startTimescale) {

let converted = amount;

if (startTimescale === 'weekly') {
if (startTimescale === `weekly`) {
converted = amount * 52;
} else if (startTimescale === 'monthly') {
} else if (startTimescale === `monthly`) {
converted = amount * 12;
} else if (startTimescale === 'yearly') {
} else if (startTimescale === `yearly`) {
// do nothing
}

return converted;
}; // End toYearlyFrom()
};


/** Returns `amount` converted from whatever 'timescale' it was before
Expand All @@ -36,16 +36,16 @@ let toMonthlyFrom = function (amount, startTimescale) {

let converted = amount;

if (startTimescale === 'weekly') {
if (startTimescale === `weekly`) {
converted = amount * (4 + (1 / 3));
} else if (startTimescale === 'monthly') {
} else if (startTimescale === `monthly`) {
// do nothing
} else if (startTimescale === 'yearly') {
} else if (startTimescale === `yearly`) {
converted = amount / 12;
}

return converted;
}; // End toMonthlyFrom()
};


/** Returns `amount` converted from whatever 'timescale' it was before
Expand All @@ -59,35 +59,35 @@ let toWeeklyFrom = function (amount, startTimescale) {

let converted = amount;

if (startTimescale === 'weekly') {
if (startTimescale === `weekly`) {
// do nothing
} else if (startTimescale === 'monthly') {
} else if (startTimescale === `monthly`) {
converted = amount / (4 + (1 / 3));
} else if (startTimescale === 'yearly') {
} else if (startTimescale === `yearly`) {
converted = amount * 52;
}

return converted;
}; // End toWeeklyFrom()
};

let timescaleMultipliers = {};

timescaleMultipliers.fromYearly = {
'Weekly': 1 / 12 / (4 + 1 / 3),
'Monthly': 1 / 12,
'Yearly': 1,
Weekly: 1 / 12 / (4 + 1 / 3),
Monthly: 1 / 12,
Yearly: 1,
};

timescaleMultipliers.fromMonthly = {
'Weekly': 1 / (4 + 1 / 3),
'Monthly': 1,
'Yearly': 12,
Weekly: 1 / (4 + 1 / 3),
Monthly: 1,
Yearly: 12,
};

timescaleMultipliers.fromWeekly = {
'Weekly': 1,
'Monthly': (4 + 1 / 3),
'Yearly': 52,
Weekly: 1,
Monthly: (4 + 1 / 3),
Yearly: 52,
};


Expand Down
5 changes: 1 addition & 4 deletions src/utils/convertForUpdate.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/**
*
*/
const convertForUpdate = function ({ name, route, ...otherProps }) {

let forUpdate = {
Expand All @@ -10,7 +7,7 @@ const convertForUpdate = function ({ name, route, ...otherProps }) {

return forUpdate;

}; // End convertForUpdate()
};


export { convertForUpdate };

0 comments on commit e4d5566

Please sign in to comment.