Skip to content
Closed
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion src/app/application.db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,15 @@ export class ApplicationDb {
if (this.apiService && this.apiService.base) {
let formData = new FormData();
if (!preformated) {
// Fields managed by the server or relational data, not to be sent in updates
const excludedFields = [
'id',
'created_at',
'updated_at',
'user_pias'
];
for (const d in entry) {
if (entry.hasOwnProperty(d)) {
if (entry.hasOwnProperty(d) && !excludedFields.includes(d)) {
let value = entry[d];
if (
d === 'data' ||
Expand Down
38 changes: 9 additions & 29 deletions src/app/services/answer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,37 +46,17 @@ export class AnswerService extends ApplicationDb {

private setFormData(data): FormData {
const formData = new FormData();
// Fields managed by the server or provided via URL route
const excludedFields = ['id', 'pia_id', 'created_at', 'updated_at'];
for (const d in data) {
if (data.hasOwnProperty(d)) {
if (data[d] instanceof Object) {
for (const d2 in data[d]) {
if (data[d].hasOwnProperty(d2)) {
if (data[d][d2] instanceof Array) {
for (const d3 in data[d][d2]) {
if (data[d].hasOwnProperty(d2)) {
if (data[d][d2][d3]) {
formData.append(
'answer[' + d + '][' + d2 + '][]',
data[d][d2][d3]
);
}
}
}
} else {
if (data[d][d2]) {
formData.append('answer[' + d + '][' + d2 + ']', data[d][d2]);
} else {
formData.append('answer[' + d + '][' + d2 + ']', '');
}
}
}
}
if (data.hasOwnProperty(d) && !excludedFields.includes(d)) {
if (d === 'data' && data[d] instanceof Object) {
// Serialize the data object as JSON (like structures)
formData.append('answer[' + d + ']', JSON.stringify(data[d]));
} else if (data[d] != null) {
formData.append('answer[' + d + ']', data[d]);
} else {
if (data[d] != null) {
formData.append('answer[' + d + ']', data[d]);
} else {
formData.append('answer[' + d + ']', '');
}
formData.append('answer[' + d + ']', '');
}
}
}
Expand Down