Fixed an issue with place property removal from object that represent metadata section field on rest side

This commit is contained in:
Giuseppe Digilio
2019-04-04 12:43:17 +02:00
parent bbc27febdd
commit 71c0c1b52c
2 changed files with 8 additions and 8 deletions

View File

@@ -27,16 +27,16 @@ export function isServerFormValue(obj: any): boolean {
&& obj.hasOwnProperty('value')
&& obj.hasOwnProperty('language')
&& obj.hasOwnProperty('authority')
&& obj.hasOwnProperty('confidence')
&& obj.hasOwnProperty('place'))
&& obj.hasOwnProperty('confidence'))
}
/**
* Export a function to normalize sections object of the server response
*
* @param obj
* @param objIndex
*/
export function normalizeSectionData(obj: any) {
export function normalizeSectionData(obj: any, objIndex?: number) {
let result: any = obj;
if (isNotNull(obj)) {
// If is an Instance of FormFieldMetadataValueObject normalize it
@@ -49,14 +49,14 @@ export function normalizeSectionData(obj: any) {
obj.language,
obj.authority,
(obj.display || obj.value),
obj.place,
obj.place || objIndex,
obj.confidence,
obj.otherInformation
);
} else if (Array.isArray(obj)) {
result = [];
obj.forEach((item, index) => {
result[index] = normalizeSectionData(item);
result[index] = normalizeSectionData(item, index);
});
} else if (typeof obj === 'object') {
result = Object.create({});
@@ -141,9 +141,9 @@ export class SubmissionResponseParsingService extends BaseResponseParsingService
// If entry is not an array, for sure is not a section of type form
if (Array.isArray(entry)) {
normalizedSectionData[metdadataId] = [];
entry.forEach((valueItem) => {
entry.forEach((valueItem, index) => {
// Parse value and normalize it
const normValue = normalizeSectionData(valueItem);
const normValue = normalizeSectionData(valueItem, index);
if (isNotEmpty(normValue)) {
normalizedSectionData[metdadataId].push(normValue);
}