From dc27bb9f089722e8bd7b029577c8cadb5e35524c Mon Sep 17 00:00:00 2001 From: dbroqua Date: Thu, 11 Apr 2019 12:47:20 +0200 Subject: [PATCH] Updated default order --- middleware/VegetableTypes.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) 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)