0

Here is my code snippet for parsing application data:

async function parseApplication(data: Application) {


const fieldGroupValues = {};
  for (const group of Object.keys(data.mappedFieldGroupValues)) {
    const groupValue = data.mappedFieldGroupValues[group];
    for (const fieldName of Object.keys(groupValue.mappedFieldValues)) {
      const { fieldValue } = groupValue.mappedFieldValues[fieldName];
  }
  return fieldGroupValues;
}

But I receive data as Promise object, how can I retrieve data from Promise?

3
  • You can use await keyword to get the result in an async function or using .then(). You can take a look at this question which probably helps: How do I return the response from an asynchronous call? Commented Oct 23, 2020 at 10:07
  • thank you! it seems like I've used it but it still not working Commented Oct 23, 2020 at 10:11
  • It seems you are combining both, you need to either use await or .then(). Commented Oct 23, 2020 at 10:13

1 Answer 1

1

In you example you are combining both of await and .then(), I would use only one of them.

Preferably await as the following:

try {
   const dict = await getDictionaryByKey(fieldValue.value.entityDefinitionCode);
   const dictItem = dict.find((item) => fieldValue.value.entityId === item.code);
   acc[fieldName] = dictItem ? dictItem.text : fieldValue.value.entityId;
} catch (err) {
   acc[fieldName] = fieldValue.value.entityId;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.