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 null value of additional entity when no additional entities are uploaded #1919

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Changes from all commits
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
17 changes: 10 additions & 7 deletions src/frontend/src/api/CreateProjectService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,34 +190,37 @@ const GenerateProjectFilesService = (url: string, projectData: any, formUpload:
let isAPISuccess = true;
try {
let response;

const additional_entities: string[] =
projectData?.additional_entities?.length > 0
? [projectData?.additional_entities?.[0]?.replaceAll(' ', '_')]
: [];

if (projectData.form_ways === 'custom_form') {
// TODO move form upload to a separate service / endpoint?
const generateApiFormData = new FormData();
generateApiFormData.append('xlsform', formUpload);

if (additional_entities?.length > 0) {
generateApiFormData.append('additional_entities', additional_entities);
}

response = await axios.post(url, generateApiFormData, {
headers: {
'Content-Type': 'multipart/form-data',
},
});
} else {
const generateApiFormData = new FormData();
generateApiFormData.append(
'additional_entities',
additional_entities?.length > 0 ? additional_entities : null,
);
response = await axios.post(url, generateApiFormData, {
const payload = {
additional_entities: additional_entities.length > 0 ? additional_entities : null,
};
response = await axios.post(url, payload, {
headers: {
'Content-Type': 'multipart/form-data',
'Content-Type': 'application/json',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done finding the problem!
It makes sense now πŸ˜„

But here I think form data was used to provide a file name, so that can give a name to the additional entity list.

Does this work correctly when using a json upload?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this works correctly. πŸŽ‰

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The form data was used because of custom xlsform upload, we don't need form data only for the additional_entities list.

},
});
}

isAPISuccess = isStatusSuccess(response.status);
if (!isAPISuccess) {
throw new Error(`Request failed with status ${response.status}`);
Expand Down
Loading