diff --git a/middleware/VegetableTypes.js b/middleware/VegetableTypes.js index cd98dd3..749b82a 100644 --- a/middleware/VegetableTypes.js +++ b/middleware/VegetableTypes.js @@ -20,7 +20,28 @@ class VegetableTypes { callback(new Error('No vegetable type found'), 204) return false } - callback(null, items) + + let res = [] + + for (let i = 0; i < items.rows.length; i += 1) { + let type = items[i].rows.toJSON() + let vegetables = [] + + for (let j = 0; j < type.Vegetables.length; j += 1) { + let k = 0 + for (k = 0; k < vegetables.length; k += 1) { + if (type.Vegetables[j].name < vegetables[k]) { + break + } + } + + vegetables.splice(k, 0, type.Vegetables[j]) + } + type.Vegetables = vegetables + res.push(type) + } + + callback(null, { count: items.count, rows: res }) }) .catch((e) => { callback(e, null)