diff --git a/middleware/Vegetables.js b/middleware/Vegetables.js index 6167e55..20b0c71 100644 --- a/middleware/Vegetables.js +++ b/middleware/Vegetables.js @@ -174,7 +174,22 @@ class Vegetables { callback(new Error('No vegetable found'), 204) return false } - callback(null, items) + + const _items = items.rows.toJSON() + let vegetables = [] + + for (let j = 0; j < _items.length; j += 1) { + let k = 0 + for (k = 0; k < vegetables.length; k += 1) { + if (_items[j].name.localeCompare(vegetables[k].name) === -1) { + break + } + } + + vegetables.splice(k, 0, _items[j]) + } + + callback(null, { count: vegetables.length, rows: vegetables }) }) .catch((e) => { callback(e, null)