« get me outta code hell

search: refactor generic process to use statements - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-05-13 11:28:32 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-05-31 12:11:53 -0300
commitb69e03084d142f530879a063f4844b1ee432e37a (patch)
treee06bc5bd1b7efb093345dcb1467233ea5e546b6a
parent3a1aa3d7232ba24725b1b9215c296747bb8b242c (diff)
search: refactor generic process to use statements
-rw-r--r--src/util/search-spec.js49
1 files changed, 28 insertions, 21 deletions
diff --git a/src/util/search-spec.js b/src/util/search-spec.js
index f9d2a035..dc58b276 100644
--- a/src/util/search-spec.js
+++ b/src/util/search-spec.js
@@ -109,42 +109,49 @@ export const searchSpec = {
         .filter(track => !track.originalReleaseTrack),
     ].flat(),
 
-    process: (thing, opts) => ({
-      primaryName:
-        thing.name,
+    process(thing, opts) {
+      const fields = {};
 
-      color:
-        thing.color,
+      fields.primaryName =
+        thing.name;
 
-      additionalNames:
+      fields.color =
+        thing.color;
+
+      fields.additionalNames =
         (Object.hasOwn(thing, 'additionalNames')
           ? thing.additionalNames.map(entry => entry.name)
        : Object.hasOwn(thing, 'aliasNames')
           ? thing.aliasNames
-          : []),
+          : []);
+
+      const contribKeys = [
+        'artistContribs',
+        'bannerArtistContribs',
+        'contributorContribs',
+        'coverArtistContribs',
+        'wallpaperArtistContribs',
+      ];
 
-      contributors:
-        ([
-          'artistContribs',
-          'bannerArtistContribs',
-          'contributorContribs',
-          'coverArtistContribs',
-          'wallpaperArtistContribs',
-        ]).filter(key => Object.hasOwn(thing, key))
+      fields.contributors =
+        contribKeys
+          .filter(key => Object.hasOwn(thing, key))
           .flatMap(key => thing[key])
           .map(contrib => contrib.artist)
-          .flatMap(artist => [artist.name, ...artist.aliasNames]),
+          .flatMap(artist => [artist.name, ...artist.aliasNames]);
 
-      groups:
+      fields.groups =
         (Object.hasOwn(thing, 'groups')
           ? thing.groups.map(group => group.name)
        : Object.hasOwn(thing, 'album')
           ? thing.album.groups.map(group => group.name)
-          : []),
+          : []);
 
-      artwork:
-        prepareArtwork(thing, opts),
-    }),
+      fields.artwork =
+        prepareArtwork(thing, opts);
+
+      return fields;
+    },
 
     index: [
       'primaryName',