Skip to content

Commit

Permalink
Merge pull request #1 from hackforla/develop
Browse files Browse the repository at this point in the history
Merge hackforla updates
  • Loading branch information
sthapa authored Nov 5, 2020
2 parents 4b0d76f + 582805d commit 8599156
Show file tree
Hide file tree
Showing 34 changed files with 1,540 additions and 539 deletions.
8 changes: 8 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@ module.exports = {
rules: {
"prettier/prettier": "error",
},
settings: {
react: {
// Version checking of react. Default is "detect", which
// fails at the root directory, since react is not installed
// here. Providing a dummy number supresses the warning
version: "16.0",
},
},
};
2 changes: 1 addition & 1 deletion app/services/account-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ const setPermissions = async (userId, permissionName, value) => {
try {
// do a tiny bit of sanity checking on our input
var booleanValue = Boolean(value);
const updateSql = `update login set ${permissionName}=$1} where id = ${userId};`;
const updateSql = `update login set ${permissionName}=$1 where id = ${userId};`;
await pool.query(updateSql, [booleanValue]);
return {
success: true,
Expand Down
44 changes: 38 additions & 6 deletions app/services/stakeholder-best-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ record has been approved, it will be the most recent version (i.e., have
If you make changes to the database structure, be sure to update these
methods as well as the corresponding methods in the stakeholder-service.js.
You can search by max/min lat, lng bounds or by a center and radius(distance),
with bounds taking precedence.
*/

const booleanEitherClause = (columnName, value) => {
Expand All @@ -27,13 +30,16 @@ const search = async ({
latitude,
longitude,
distance,
maxLat,
maxLng,
minLat,
minLng,
isInactive,
verificationStatusId,
tenantId,
}) => {
const locationClause = buildLocationClause(latitude, longitude);
const categoryClause = buildCTEClause(categoryIds, "");

const sql = `${categoryClause}
select s.id, s.name, s.address_1, s.address_2, s.city, s.state, s.zip,
s.phone, s.latitude, s.longitude, s.website, s.notes,
Expand Down Expand Up @@ -62,16 +68,20 @@ const search = async ({
s.donation_delivery_instructions, s.donation_notes, s.covid_notes,
s.category_notes, s.eligibility_notes, s.food_types, s.languages,
s.v_name, s.v_categories, s.v_address, s.v_phone, s.v_email,
s.v_hours, s.verification_status_id, s.inactive_temporary,
s.v_hours, s.v_food_types, s.verification_status_id, s.inactive_temporary,
array_to_json(s.hours) as hours, s.category_ids,
s.neighborhood_id, s.is_verified,
s.food_bakery, s.food_dry_goods, s.food_produce,
s.food_dairy, s.food_prepared, s.food_meat,
${locationClause ? `${locationClause} AS distance,` : ""}
${buildLoginSelectsClause()}
from stakeholder_set as s
${buildLoginJoinsClause()}
where s.tenant_id = ${tenantId}
where s.tenant_id = ${tenantId}
${
Number(distance) && locationClause
maxLat && maxLng && minLat && minLng
? buildBounds({ maxLat, maxLng, minLat, minLng })
: Number(distance) && locationClause
? `AND ${locationClause} < ${distance}`
: ""
}
Expand All @@ -83,7 +93,6 @@ const search = async ({
}
order by distance
`;
// console.log(sql);
let stakeholders = [];
let categoriesResults = [];
var stakeholderResult, stakeholder_ids;
Expand Down Expand Up @@ -173,6 +182,12 @@ const search = async ({
covidNotes: row.covid_notes || "",
categoryNotes: row.category_notes || "",
eligibilityNotes: row.eligibility_notes || "",
foodBakery: row.food_bakery,
foodDryGoods: row.food_dry_goods,
foodProduce: row.food_produce,
foodDairy: row.food_dairy,
foodPrepared: row.food_prepared,
foodMeat: row.food_meat,
foodTypes: row.food_types || "",
languages: row.languages || "",
confirmedName: row.v_name,
Expand All @@ -181,6 +196,7 @@ const search = async ({
confirmedPhone: row.v_phone,
confirmedEmail: row.v_email,
confirmedHours: row.v_hours,
confirmedFoodTypes: row.v_food_types,
verificationStatusId: row.verification_status_id,
inactiveTemporary: row.inactive_temporary,
neighborhoodId: row.neighborhood_id,
Expand Down Expand Up @@ -224,8 +240,10 @@ const selectById = async (id) => {
s.donation_delivery_instructions, s.donation_notes, s.covid_notes,
s.category_notes, s.eligibility_notes, s.food_types, s.languages,
s.v_name, s.v_categories, s.v_address, s.v_phone, s.v_email,
s.v_hours, s.verification_status_id, s.inactive_temporary,
s.v_hours, s.v_food_types, s.verification_status_id, s.inactive_temporary,
s.neighborhood_id, s.is_verified,
s.food_bakery, s.food_dry_goods, s.food_produce,
s.food_dairy, s.food_prepared, s.food_meat,
${buildLoginSelectsClause()}
from stakeholder_best s
${buildLoginJoinsClause()}
Expand Down Expand Up @@ -296,6 +314,12 @@ const selectById = async (id) => {
covidNotes: row.covid_notes || "",
categoryNotes: row.category_notes || "",
eligibilityNotes: row.eligibility_notes || "",
foodBakery: row.food_bakery,
foodDryGoods: row.food_dry_goods,
foodProduce: row.food_produce,
foodDairy: row.food_dairy,
foodPrepared: row.food_prepared,
foodMeat: row.food_meat,
foodTypes: row.food_types || "",
languages: row.languages || "",
confirmedName: row.v_name,
Expand All @@ -304,6 +328,7 @@ const selectById = async (id) => {
confirmedPhone: row.v_phone,
confirmedEmail: row.v_email,
confirmedHours: row.v_hours,
confirmedFoodTypes: row.v_food_types,
verificationStatusId: row.verification_status_id,
inactiveTemporary: row.inactive_temporary,
neighborhoodId: row.neighborhood_id,
Expand Down Expand Up @@ -349,6 +374,13 @@ const buildLocationClause = (latitude, longitude) => {
return locationClause;
};

const buildBounds = ({ maxLat, maxLng, minLat, minLng }) => {
return `
AND s.latitude BETWEEN ${minLat} AND ${maxLat}
AND s.longitude BETWEEN ${minLng} AND ${maxLng}
`;
};

const buildLoginJoinsClause = () => {
return `
left join login L1 on s.created_login_id = L1.id
Expand Down
11 changes: 10 additions & 1 deletion app/services/stakeholder-log-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ const selectById = async (id) => {
s.donation_delivery_instructions, s.donation_notes, s.covid_notes,
s.category_notes, s.eligibility_notes, s.food_types, s.languages,
s.v_name, s.v_categories, s.v_address, s.v_phone, s.v_email,
s.v_hours, s.verification_status_id, s.inactive_temporary,
s.v_hours, s.v_food_types, s.verification_status_id, s.inactive_temporary,
s.neighborhood_id,
s.food_bakery, s.food_dry_goods, s.food_produce,
s.food_dairy, s.food_prepared, s.food_meat,
${buildLoginSelectsClause()}
from stakeholder_log s
${buildLoginJoinsClause()}
Expand Down Expand Up @@ -107,11 +109,18 @@ const selectById = async (id) => {
confirmedPhone: row.v_phone,
confirmedEmail: row.v_email,
confirmedHours: row.v_hours,
confirmedFoodTypes: row.v_food_types,
verificationStatusId: row.verification_status_id,
inactiveTemporary: row.inactive_temporary,
neighborhoodId: row.neighborhood_id,
neighborhoodName: row.neighborhood_name,
completeCriticalPercent: row.complete_critical_percent,
foodBakery: row.food_bakery,
foodDryGoods: row.food_dry_goods,
foodProduce: row.food_produce,
foodDairy: row.food_dairy,
foodPrepared: row.food_prepared,
foodMeat: row.food_meat,
});
});

Expand Down
Loading

0 comments on commit 8599156

Please sign in to comment.