Hello,
I have a list of documents related with reports of validations applied to items, on this case I need to select the reports that include a certain product “p00”, currently this WHERE condition is working fine.
The issue happens when returning a productStatus depending if the product has an item wiith a validation error with a certain severity: Severity > 1 should return “Errors”, Severity > 0 should return “Warnings” and ELSE condition Success.
This is my document :
{
id: "1",
description: "Report of error of channel X",
overallStatus: "Error",
okItems: [
{
item: {
id: "p00-item01"
product: {
id: "p00"
}
},
}
]
validationErrors: [
{
item: {
id: "p00-item00"
product: {
id: "p00"
}
},
errors: [
{
severity: 2,
description: "Some validation error"
},
{
severity: 2,
description: "Some other validation error"
},
{
severity: 1,
description: "Minor validation error"
},
{
severity: 1,
description: "Other type minor validation error"
},
]
},
{
item: {
id: "p05-item01"
product: {
id: "p05"
}
},
errors: [
{
severity: 1,
description: "Some validation error"
},
{
severity: 1,
description: "Some other validation error"
},
]
}
]
}
Please take a look on my query:
SELECT
meta(er).id as id, description,
CASE
WHEN (
ANY validationError IN er.validationErrors SATISFIES
validationError.item.product.id = 'p00' AND
(ANY error IN errors SATISFIES
error.severity > 1 END)
END) THEN "Error"
WHEN (
ANY validationError IN er.validationErrors SATISFIES
validationError.item.product.id = 'p00' AND
(ANY error IN errors SATISFIES
error.severity > 0 END)
END) THEN "Warnings"
ELSE
"Successs"
END AS ProductStatus
FROM `Lucky_Bucket` AS er
WHERE
er.type = 'exportr'
AND
(
ANY validationError IN er.validationErrors SATISFIES
validationError.item.product.id = 'p00'
END
)
The desired result should be on this case:
[
{
id: "1",
description: "Report of error of channel X",
productStatus: "Error"
}
]
On this case the couchbase version is 6.6