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..0c3704ed3 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"), @@ -256,7 +255,7 @@ export default function WorkForm({ ...props }) { > - Responsible Ministry + Responsible Ministry { 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 );