diff --git a/middleware/VegetableTypes.js b/middleware/VegetableTypes.js index f09a7ae..cf8596e 100644 --- a/middleware/VegetableTypes.js +++ b/middleware/VegetableTypes.js @@ -77,7 +77,24 @@ class VegetableTypes { callback(new Error('Item vegetable type not found'), 404) return false } - callback(null, item) + + let type = item.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].name) { + console.log('Break at:', k) + break + } + } + + vegetables.splice(k, 0, type.Vegetables[j]) + } + type.Vegetables = vegetables + + callback(null, type) }) .catch((e) => { callback(e, null)