Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
Add migration
Browse files Browse the repository at this point in the history
  • Loading branch information
albertkol committed Nov 19, 2024
1 parent 1d86035 commit aee7aed
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 8 deletions.
13 changes: 5 additions & 8 deletions api/routes/application/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,6 @@ def post_request_changes(self, application_id: str):
as_json=True,
include_forms=True,
)

except NoResultFound:
return {
"code": 404,
Expand All @@ -436,10 +435,7 @@ def post_request_changes(self, application_id: str):

args = request.get_json()
field_ids = args["field_ids"]
# column needs adding
# feedback_message = args["feedback_message"]

print("Fields needing status update: ", field_ids)
feedback_message = args["feedback_message"]

application_requires_changes = False
for application_form in application["forms"]:
Expand All @@ -452,23 +448,24 @@ def post_request_changes(self, application_id: str):
if field["key"] in field_ids:
from_requires_changes = True
application_requires_changes = True
forms_json_queston["status"] = "NOT_STARTED"
forms_json_queston["status"] = "CHANGES_REQUESTED"

forms_json_queston["fields"] = [field]
forms_json.append(forms_json_queston)

if from_requires_changes:
form_patch_fields = {
"json": forms_json,
"status": "NOT_STARTED",
"status": "CHANGES_REQUESTED",
"has_completed": False,
"feedback_message": feedback_message,
}

patch_form(application_id, application_form["name"], form_patch_fields)

if application_requires_changes:
application_patch_fields = {
"status": "NOT_STARTED",
"status": "CHANGES_REQUESTED",
}

patch_application(application_id, application_patch_fields)
29 changes: 29 additions & 0 deletions db/migrations/versions/4a40deca2d61_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""empty message
Revision ID: 4a40deca2d61
Revises: eb61bc354c57
Create Date: 2024-11-19 18:51:54.942195
"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "4a40deca2d61"
down_revision = "eb61bc354c57"
branch_labels = None
depends_on = None


def upgrade():
op.execute("ALTER TYPE status ADD VALUE 'CHANGES_REQUESTED'")

with op.batch_alter_table("forms", schema=None) as batch_op:
batch_op.add_column(sa.Column("feedback_message", sa.String(), nullable=True))


def downgrade():
# remove CHANGES_REQUESTED from the status enum is a bit harder

with op.batch_alter_table("forms", schema=None) as batch_op:
batch_op.drop_column("feedback_message")
1 change: 1 addition & 0 deletions db/models/application/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ class Status(Enum):
IN_PROGRESS = 1
SUBMITTED = 2
COMPLETED = 3
CHANGES_REQUESTED = 4
1 change: 1 addition & 0 deletions db/models/forms/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ class Status(Enum):
IN_PROGRESS = 1
SUBMITTED = 2
COMPLETED = 3
CHANGES_REQUESTED = 4
2 changes: 2 additions & 0 deletions db/models/forms/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ class Forms(BaseModel):
status = db.Column("status", db.Enum(Status), default="NOT_STARTED", nullable=False)
name = db.Column("name", db.String(), nullable=False)
has_completed = db.Column("has_completed", db.Boolean(), default=False)
feedback_message = db.Column("feedback_message", db.String(), nullable=True)

def as_json(self):
return {
"status": self.status.name,
"name": self.name,
"questions": self.json,
"feedback_message": self.feedback_message,
}
1 change: 1 addition & 0 deletions db/queries/form/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def patch_form(application_id: str, name, patch_fields: dict) -> Forms:
form.json = patch_fields.get("json", form.json)
form.status = patch_fields.get("status", form.status)
form.has_completed = patch_fields.get("has_completed", form.has_completed)
form.feedback_message = patch_fields.get("feedback_message", form.feedback_message)

db.session.commit()

Expand Down

0 comments on commit aee7aed

Please sign in to comment.