1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

M #-: Fix apiResponse data handling (#3268)

- If the API response returns only 1 object, it won't be array wrapped,
  causing issues when formatting the response to a dataset. Now
  transformApiResponseToDataset always casts the response to an array.

Signed-off-by: Victor Hansson <vhansson@opennebula.io>
(cherry picked from commit 51ef95d720b996f5629e749ff17e9b8307cd18fe)
This commit is contained in:
vichansson 2024-10-18 15:42:54 +03:00 committed by Tino Vázquez
parent 1f003cbcd5
commit c4746824d8
No known key found for this signature in database
GPG Key ID: 14201E424D02047E

View File

@ -114,12 +114,13 @@ export const transformApiResponseToDataset = (
depth = 0,
dataArrayPath
) => {
const dataArray =
const dataArray = _.castArray(
(_.isEmpty(apiResponse)
? []
: dataArrayPath
? _.get(apiResponse, dataArrayPath)
: findFirstArray(apiResponse, depth)) ?? []
)
const flattenObject = (obj, prefix = '') =>
Object.keys(obj).reduce((acc, k) => {