Skip to content

Commit

Permalink
fix: update project form
Browse files Browse the repository at this point in the history
  • Loading branch information
Sujanadh committed Nov 12, 2024
1 parent 831f055 commit 12943a4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
31 changes: 23 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,12 +849,13 @@ 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.
"""
project = project_user_dict["project"]
user = project_user_dict["user"]

# TODO we currently do nothing with the provided category
# TODO allowing for category updates is disabled due to complexity
Expand All @@ -876,16 +877,30 @@ async def update_project_form(
)

sql = """
INSERT INTO projects
(xlsform_content)
VALUES
(%(xls_data)s)
UPDATE projects
SET
xlsform_content = %(xls_data)s,
author_id = %(author_id)s,
short_description = %(text)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(),
"author_id": user.id,
"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
5 changes: 3 additions & 2 deletions src/frontend/src/api/CreateProjectService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const CreateProjectService = (
}

// Generate project files
console.log('additional entity', [additionalFeature?.name?.split('.')?.[0]]);
const generateProjectFile = await dispatch(
GenerateProjectFilesService(
`${import.meta.env.VITE_API_URL}/projects/${projectId}/generate-project-data`,
Expand Down Expand Up @@ -448,14 +449,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 12943a4

Please sign in to comment.