Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2121 suggestion correction db #2164

Merged
merged 6 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/src/components/Admin/Suggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const columns = [
{ id: "name", label: "Name", minWidth: 100 },
{ id: "notes", label: "Notes", minWidth: 10 },
{ id: "suggestionStatusId", label: "Status", minWidth: 10 },
{ id: "formType", label: "Type", minWidth: 10 },
];

const FILTERS = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,25 +173,12 @@ const CorrectionForm = withFormik({
hours: formatArrayToString(org.hours),
category: formatArrayToString(org.categories),
tenantId: org.tenantId,
};

const stakeholder = {
...orgDetails,
};

// Construct the suggestion by starting with the stakeholder record,
// adding values from the suggestion form properties, and then
// moving the original stakeholder.id to be the stakeholderId property
// of the suggestion
const altered = {
...stakeholder,
formType: "correction",
...values,
stakeholderId: stakeholder.id,
id: null,
};

return suggestionService
.post(altered)
.post(orgDetails)
.then(() => {
formikBag.props.setToast({
message: "Thank you for your help!",
Expand Down
6 changes: 5 additions & 1 deletion client/src/components/FoodSeeker/Suggestion.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,15 @@ function Suggestion(props) {
</Grid>
<Grid item>
<Formik
initialValues={DEFAULT_STAKEHOLDER}
initialValues={{
...DEFAULT_STAKEHOLDER,
formType: "suggestion",
}}
validationSchema={validationSchema}
onSubmit={async (value, formikBag) => {
formikBag.setSubmitting(true);
return suggestionService

.post(value)
.then(() => {
formikBag.setSubmitting(false);
Expand Down
1 change: 1 addition & 0 deletions client/src/constants/stakeholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ export const DEFAULT_STAKEHOLDER = {
tipsterPhone: "",
tipsterEmail: "",
category: "",
formType: "",
};
8 changes: 4 additions & 4 deletions server/app/services/suggestion-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const selectAll = async (params: {
select id, name, address_1, address_2, city, state, zip,
phone, email, notes,
tipster_name, tipster_phone, tipster_email,
hours, category, suggestion_status_id, admin_notes, tenant_id
hours, category, suggestion_status_id, admin_notes, tenant_id, form_type
from suggestion
where suggestion_status_id = any ($<statusIds>)
and tenant_id = $<tenantId>
Expand All @@ -36,7 +36,7 @@ const selectById = async (suggestionId: string): Promise<Suggestion> => {
select id, name, address_1, address_2, city, state, zip,
phone, email, notes,
tipster_name, tipster_phone, tipster_email,
hours, category, suggestion_status_id, admin_notes, tenant_id
hours, category, suggestion_status_id, admin_notes, tenant_id, form_type
from suggestion where id = $<id>`;

const row: Suggestion = await db.one(sql, { id });
Expand All @@ -50,13 +50,13 @@ const insert = async (model: SuggestionPostFields): Promise<{ id: number }> => {
city, state, zip,
phone, email, notes,
tipster_name, tipster_phone, tipster_email,
hours, category, tenant_id, stakeholder_id
hours, category, tenant_id, stakeholder_id, form_type
) values (
$<name>, $<address1>, $<address2>,
$<city>, $<state>, $<zip>,
$<phone>, $<email>, $<notes>,
$<tipsterName>, $<tipsterPhone>, $<tipsterEmail>,
$<hours>, $<category>, $<tenantId>, $<stakeholderId>
$<hours>, $<category>, $<tenantId>, $<stakeholderId>, $<formType>
)
returning id`;
const result = await db.one(sql, { ...model, suggestionStatusId: 1 });
Expand Down
24 changes: 24 additions & 0 deletions server/app/validation-schema/suggestion-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ export const suggestionPostRequestSchema: JSONSchemaType<SuggestionPostFields> =
type: "integer",
minimum: 1,
},
formType: {
oneOf: [
{
const: "suggestion",
title: "Suggestion",
},
{
const: "correction",
title: "Correction",
},
],
},
},
additionalProperties: true,
};
Expand Down Expand Up @@ -142,6 +154,18 @@ export const suggestionPutRequestSchema: JSONSchemaType<Suggestion> = {
type: "integer",
minimum: 1,
},
formType: {
oneOf: [
{
const: "suggestion",
title: "Suggestion",
},
{
const: "correction",
title: "Correction",
},
],
},
},
additionalProperties: false,
};
23 changes: 23 additions & 0 deletions server/migrations/1719365294499_alter-suggestion-table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* eslint-disable camelcase */
exports.shorthands = undefined;

const formTypeTyping = {
Suggestion: "suggestion",
Correction: "correction",
};
exports.up = (pgm) => {
pgm.addColumn("suggestion", {
form_type: {
type: "text",
default: formTypeTyping.Suggestion,
},
});
};

exports.down = (pgm) => {
pgm.dropColumns("suggestion", {
form_type: {
ifExists: true,
},
});
};
6 changes: 6 additions & 0 deletions server/types/suggestion-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ export interface Suggestion {
adminNotes: string;
stakeholderId: number;
tenantId: number;
formType: formTypeTyping;
}

export enum formTypeTyping {
Suggestion = "suggestion",
Correction = "correction",
}