From ec9f1a0da41b969cf34120132be2184e79c45e61 Mon Sep 17 00:00:00 2001 From: Tom Chapman Date: Mon, 18 Dec 2023 15:17:14 -0800 Subject: [PATCH 1/2] WIP --- ...5cb91595d6a_make_work_ministry_nullable.py | 25 +++++++++++++++++++ epictrack-api/src/api/models/work.py | 2 +- .../src/api/schemas/request/work_request.py | 2 +- .../src/components/work/WorkForm.tsx | 1 - .../src/components/work/WorkList.tsx | 2 +- 5 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 epictrack-api/migrations/versions/65cb91595d6a_make_work_ministry_nullable.py diff --git a/epictrack-api/migrations/versions/65cb91595d6a_make_work_ministry_nullable.py b/epictrack-api/migrations/versions/65cb91595d6a_make_work_ministry_nullable.py new file mode 100644 index 000000000..4f96a660b --- /dev/null +++ b/epictrack-api/migrations/versions/65cb91595d6a_make_work_ministry_nullable.py @@ -0,0 +1,25 @@ +"""make work ministry nullable + +Revision ID: 65cb91595d6a +Revises: 925ba8974e38 +Create Date: 2023-12-18 14:57:36.523607 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '65cb91595d6a' +down_revision = '925ba8974e38' +branch_labels = None +depends_on = None + + +def upgrade(): + op.alter_column('works', 'ministry_id', existing_type=sa.INTEGER(), nullable=True) + op.alter_column('works_history', 'ministry_id', existing_type=sa.INTEGER(), nullable=True) + + +def downgrade(): + pass diff --git a/epictrack-api/src/api/models/work.py b/epictrack-api/src/api/models/work.py index 10d5a22bb..be4ce722e 100644 --- a/epictrack-api/src/api/models/work.py +++ b/epictrack-api/src/api/models/work.py @@ -67,7 +67,7 @@ class Work(BaseModelVersioned): work_decision_date = Column(DateTime(timezone=True)) project_id = Column(ForeignKey('projects.id'), nullable=False) - ministry_id = Column(ForeignKey('ministries.id'), nullable=False) + ministry_id = Column(ForeignKey('ministries.id'), nullable=True) ea_act_id = Column(ForeignKey('ea_acts.id'), nullable=False) eao_team_id = Column(ForeignKey('eao_teams.id'), nullable=False) federal_involvement_id = Column(ForeignKey('federal_involvements.id'), nullable=False) diff --git a/epictrack-api/src/api/schemas/request/work_request.py b/epictrack-api/src/api/schemas/request/work_request.py index 716a63005..c7bacec7d 100644 --- a/epictrack-api/src/api/schemas/request/work_request.py +++ b/epictrack-api/src/api/schemas/request/work_request.py @@ -62,7 +62,7 @@ class WorkBodyParameterSchema(RequestBodyParameterSchema): ministry_id = fields.Int( metadata={"description": "Ministry id of the work"}, validate=validate.Range(min=1), - required=True, + required=False, ) federal_involvement_id = fields.Int( metadata={"description": "Federal involvement id of the work"}, diff --git a/epictrack-web/src/components/work/WorkForm.tsx b/epictrack-web/src/components/work/WorkForm.tsx index 74d4b62bc..29fe32c58 100644 --- a/epictrack-web/src/components/work/WorkForm.tsx +++ b/epictrack-web/src/components/work/WorkForm.tsx @@ -33,7 +33,6 @@ const schema = yup.object().shape({ work_type_id: yup.number().required("Work type is required"), start_date: yup.date().required("Start date is required"), project_id: yup.number().required("Project is required"), - ministry_id: yup.number().required("Responsible ministry is required"), federal_involvement_id: yup .number() .required("Federal Involvement is required"), diff --git a/epictrack-web/src/components/work/WorkList.tsx b/epictrack-web/src/components/work/WorkList.tsx index f355d16be..0f4d89428 100644 --- a/epictrack-web/src/components/work/WorkList.tsx +++ b/epictrack-web/src/components/work/WorkList.tsx @@ -66,7 +66,7 @@ const WorkList = () => { const codes = works // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - .map((w) => w[key][accessor]) + .map((w) => (w[key] ? w[key][accessor] : null)) .filter( (ele, index, arr) => arr.findIndex((t) => t === ele) === index && ele ); From c5d1250b9b98ce94d69017572db93a4faeff81df Mon Sep 17 00:00:00 2001 From: Tom Chapman Date: Tue, 19 Dec 2023 08:20:50 -0800 Subject: [PATCH 2/2] remove required from input --- epictrack-web/src/components/work/WorkForm.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/epictrack-web/src/components/work/WorkForm.tsx b/epictrack-web/src/components/work/WorkForm.tsx index 29fe32c58..0c3704ed3 100644 --- a/epictrack-web/src/components/work/WorkForm.tsx +++ b/epictrack-web/src/components/work/WorkForm.tsx @@ -255,7 +255,7 @@ export default function WorkForm({ ...props }) { > - Responsible Ministry + Responsible Ministry