From 0134087eee9261eb5d407e8f6b1b585d340e2c6d Mon Sep 17 00:00:00 2001 From: dbroqua Date: Thu, 11 Apr 2019 13:20:05 +0200 Subject: [PATCH] Fixed ASC --- middleware/VegetableTypes.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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)