Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix update project xlsform SQL after backend refactor #1872

Merged
merged 3 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
spwoodcock marked this conversation as resolved.
Show resolved Hide resolved
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]]);
spwoodcock marked this conversation as resolved.
Show resolved Hide resolved
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