Ver código fonte

dict with key

Alan Colon 7 anos atrás
pai
commit
28450b2280
1 arquivos alterados com 4 adições e 1 exclusões
  1. 4 1
      lib/util.js

+ 4 - 1
lib/util.js

@@ -30,10 +30,13 @@ const sanitize = _.curry(async (req, data) => {
   return data
 })
 
-const dict = (collection) => {
+const dict = (collection, fields) => {
   collection.forEach(item => {
     collection[item.key] = item
     collection[item.id] = item
+    if (Array.isArray(fields)) {
+      fields.forEach(field => collection[item[field]] = field)
+    }
   })
   return collection
 }