Skip to content

Commit

Permalink
fix(backend): update project xlsform SQL after backend refactor (#1872)
Browse files Browse the repository at this point in the history
* fix: update project form

* remove console log

* fix: refactored sql to update project form
  • Loading branch information
Sujanadh authored Nov 13, 2024
1 parent ef3193d commit 510dfb0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
27 changes: 19 additions & 8 deletions src/backend/app/projects/project_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ async def generate_files(
xlsform_upload: Annotated[
Optional[BytesIO], Depends(central_deps.read_optional_xlsform)
],
additional_entities: list[str] = None,
additional_entities: Optional[list[str]] = None,
):
"""Generate additional content to initialise the project.
Expand Down Expand Up @@ -849,7 +849,7 @@ async def update_project_form(
project_user_dict: Annotated[ProjectUserDict, Depends(project_manager)],
xform_id: str = Form(...),
category: XLSFormType = Form(...),
) -> DbProject:
):
"""Update the XForm data in ODK Central.
Also updates the category and custom XLSForm data in the database.
Expand All @@ -876,16 +876,27 @@ async def update_project_form(
)

sql = """
INSERT INTO projects
(xlsform_content)
VALUES
(%(xls_data)s)
UPDATE projects
SET
xlsform_content = %(xls_data)s
WHERE
id = %(project_id)s
RETURNING id, hashtags;
"""
async with db.cursor() as cur:
await cur.execute(sql, {"xls_data": xlsform.getvalue()})
await cur.execute(
sql,
{
"xls_data": xlsform.getvalue(),
"project_id": project.id,
},
)
db.commit()

return project
return JSONResponse(
status_code=HTTPStatus.OK,
content={"message": f"Successfully updated the form for project {project.id}"},
)


@router.get("/{project_id}/download")
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/src/api/CreateProjectService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,14 +448,14 @@ const PostFormUpdate = (url: string, projectData: Record<string, any>) => {
formFormData.append('xlsform', projectData.upload);

const postFormUpdateResponse = await axios.post(url, formFormData);
const resp: ProjectDetailsModel = postFormUpdateResponse.data;
const resp: { message: string } = postFormUpdateResponse.data;
// dispatch(CreateProjectActions.SetIndividualProjectDetails(modifiedResponse));
// dispatch(CreateProjectActions.SetPostFormUpdate(resp));
dispatch(CreateProjectActions.SetPostFormUpdateLoading(false));
dispatch(
CommonActions.SetSnackBar({
open: true,
message: 'Form Successfully Updated',
message: resp.message,
variant: 'success',
duration: 2000,
}),
Expand Down

0 comments on commit 510dfb0

Please sign in to comment.