Skip to content

Commit

Permalink
1154 show only specific categories to food seekers (#2133)
Browse files Browse the repository at this point in the history
* Show only specific categories to food seekers

* Undo changes to StakeholderPreview, StakeholderDetails

* Modify StakeholderPreview and StakeholderDetails components
  • Loading branch information
entrotech authored Apr 23, 2024
1 parent 33f2eac commit 30c65c7
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -325,41 +325,43 @@ const StakeholderDetails = ({ onBackClick, isDesktop }) => {
marginTop="8px"
sx={{ gap: "16px" }}
>
{selectedOrganization.categories.map((category, index) => (
<Stack
direction="row"
alignItems="center"
spacing={1}
useflexgap="true"
key={`${index}-${category}`}
sx={{
order:
category.id === MEAL_PROGRAM_CATEGORY_ID
? -1
: undefined,
}}
>
{category.id === FOOD_PANTRY_CATEGORY_ID ? (
<AppleIcon />
) : category.id === MEAL_PROGRAM_CATEGORY_ID ? (
<ForkIcon />
) : (
""
)}

<Typography
variant="body2"
key={selectedOrganization.id + category.id}
{selectedOrganization.categories
.filter((c) => c.isForFoodSeeker)
.map((category, index) => (
<Stack
direction="row"
alignItems="center"
spacing={1}
useflexgap="true"
key={`${index}-${category}`}
sx={{
margin: "0.25em 0",
marginRight: "0.25em",
fontWeight: "600",
order:
category.id === MEAL_PROGRAM_CATEGORY_ID
? -1
: undefined,
}}
>
{category.name}
</Typography>
</Stack>
))}
{category.id === FOOD_PANTRY_CATEGORY_ID ? (
<AppleIcon />
) : category.id === MEAL_PROGRAM_CATEGORY_ID ? (
<ForkIcon />
) : (
""
)}

<Typography
variant="body2"
key={selectedOrganization.id + category.id}
sx={{
margin: "0.25em 0",
marginRight: "0.25em",
fontWeight: "600",
}}
>
{category.name}
</Typography>
</Stack>
))}
</Stack>

<Box textAlign="left">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,39 +202,43 @@ const StakeholderPreview = ({ stakeholder, onSelect, isDesktop }) => {
sx={{ gap: "16px" }}
onClick={() => handleSelectOrganization(stakeholder)}
>
{stakeholder.categories.map((category, index) => (
<Stack
direction="row"
alignItems="center"
spacing={1}
useflexgap="true"
key={`${index}-${category}`}
sx={{
order:
category.id === MEAL_PROGRAM_CATEGORY_ID ? -1 : undefined,
}}
>
{category.id === FOOD_PANTRY_CATEGORY_ID ? (
<AppleIcon />
) : category.id === MEAL_PROGRAM_CATEGORY_ID ? (
<ForkIcon />
) : (
""
)}

<Typography
variant="body2"
key={stakeholder.id + category.id}
{stakeholder.categories
.filter((c) => c.isForFoodSeeker)
.map((category, index) => (
<Stack
direction="row"
alignItems="center"
spacing={1}
useflexgap="true"
key={`${index}-${category}`}
sx={{
margin: "0.25em 0",
marginRight: "0.25em",
fontWeight: "600",
order:
category.id === MEAL_PROGRAM_CATEGORY_ID
? -1
: undefined,
}}
>
{category.name}
</Typography>
</Stack>
))}
{category.id === FOOD_PANTRY_CATEGORY_ID ? (
<AppleIcon />
) : category.id === MEAL_PROGRAM_CATEGORY_ID ? (
<ForkIcon />
) : (
""
)}

<Typography
variant="body2"
key={stakeholder.id + category.id}
sx={{
margin: "0.25em 0",
marginRight: "0.25em",
fontWeight: "600",
}}
>
{category.name}
</Typography>
</Stack>
))}
</Stack>

<Box
Expand Down
4 changes: 2 additions & 2 deletions server/app/services/category-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import camelcaseKeys from "camelcase-keys";

const selectAll = async (): Promise<Category[]> => {
const sql = `
select id, name, display_order, inactive
select id, name, display_order, inactive, is_for_food_seeker
from category
order by name
`;
Expand All @@ -13,7 +13,7 @@ const selectAll = async (): Promise<Category[]> => {
};

const selectById = async (id: string): Promise<Category> => {
const sql = `select id, name, display_order as displayOrder, inactive
const sql = `select id, name, display_order as displayOrder, inactive, is_for_food_seeker
from category where id = $<id>`;

const row: Category = await db.one(sql, { id: Number(id) });
Expand Down
50 changes: 44 additions & 6 deletions server/app/services/stakeholder-best-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const selectAll = async ({ tenantId }: { tenantId: string }) => {
if (stakeholder_ids.length) {
// Hoover up all the stakeholder categories
// for all of our stakeholder row results.
const categoriesSql = `select sc.stakeholder_id, c.id, c.name, c.display_order
const categoriesSql = `select sc.stakeholder_id, c.id, c.name, c.display_order, c.is_for_food_seeker
from category c
join stakeholder_best_category sc on c.id = sc.category_id
where sc.stakeholder_id in (${stakeholder_ids.join(",")})
Expand All @@ -86,7 +86,12 @@ const selectAll = async ({ tenantId }: { tenantId: string }) => {
categories: categories
.filter((cr) => cr.stakeholder_id === row.id)
.map((c) => {
return { id: c.id, name: c.name, displayOrder: c.display_order };
return {
id: c.id,
name: c.name,
displayOrder: c.display_order,
isForFoodSeeker: c.is_for_food_seeker,
};
}),
});
});
Expand Down Expand Up @@ -182,7 +187,7 @@ const search = async ({
if (stakeholder_ids.length) {
// Hoover up all the stakeholder categories
// for all of our stakeholder row results.
const categoriesSql = `select sc.stakeholder_id, c.id, c.name, c.display_order
const categoriesSql = `select sc.stakeholder_id, c.id, c.name, c.display_order, c.is_for_food_seeker
from category c
join stakeholder_best_category sc on c.id = sc.category_id
where sc.stakeholder_id in (${stakeholder_ids.join(",")})
Expand All @@ -197,7 +202,12 @@ const search = async ({
categories
.filter((cr) => cr.stakeholder_id === row.id)
.map((c) => {
return { id: c.id, name: c.name, displayOrder: c.display_order };
return {
id: c.id,
name: c.name,
displayOrder: c.display_order,
isForFoodSeeker: c.is_for_food_seeker,
};
})
),
isVerified: row.is_verified,
Expand All @@ -214,7 +224,7 @@ const selectById = async (id: string): Promise<StakeholderBest> => {
array_to_json(s.hours) as hours,
(select array(select row_to_json(category_row)
from (
select c.id, c.name, c.display_order
select c.id, c.name, c.display_order, c.is_for_food_seeker
from category c
join stakeholder_best_category sc on c.id = sc.category_id
where sc.stakeholder_id = s.id
Expand Down Expand Up @@ -253,8 +263,36 @@ const selectById = async (id: string): Promise<StakeholderBest> => {
where s.id = ${Number(id)}`;
const row = await db.one(sql);

let categories: StakeholderCategory[] = [];

const rows = await db.manyOrNone(sql);
const stakeholder_ids = rows.map((a) => a.id);

if (stakeholder_ids.length) {
// Hoover up all the stakeholder categories
// for all of our stakeholder row results.
const categoriesSql = `select sc.stakeholder_id, c.id, c.name, c.display_order, c.is_for_food_seeker
from category c
join stakeholder_best_category sc on c.id = sc.category_id
where sc.stakeholder_id = ${row.id}
order by c.display_order, c.name`;
categories = await db.manyOrNone(categoriesSql);
}

return {
...stakeholderHelpers.rowToStakeholder(row),
...stakeholderHelpers.rowToStakeholder(
row,
categories
.filter((cr) => cr.stakeholder_id === row.id)
.map((c) => {
return {
id: c.id,
name: c.name,
displayOrder: c.display_order,
isForFoodSeeker: c.is_for_food_seeker,
};
})
),
isVerified: row.is_verified,
distance: row.distance,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* eslint-disable camelcase */

exports.shorthands = undefined;

exports.up = (pgm) => {
pgm.sql(`UPDATE Category SET is_for_food_seeker = false;
UPDATE Category SET is_for_food_seeker = true
WHERE id in (1,9,7,8,10 );`);
};

exports.down = (pgm) => {};
1 change: 1 addition & 0 deletions server/types/category-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export interface Category {
displayOrder: number;
inactive: boolean;
suggestionStatusId?: number;
isForFoodSeeker: boolean;
}
1 change: 1 addition & 0 deletions server/types/stakeholder-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface StakeholderCategory {
id: number;
name: string;
display_order: number;
is_for_food_seeker: boolean;
}

// Interface with common properties for all the full stakeholder types.
Expand Down

0 comments on commit 30c65c7

Please sign in to comment.