« get me outta code hell

generateArtistInfoPageOtherArtistLinks.js « dependencies « content « src - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/generateArtistInfoPageOtherArtistLinks.js
blob: dcee9c006e9eeeaa7c2d4c7f2f5ec1ec6e7da10b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import {unique} from '#sugar';

export default {
  contentDependencies: ['linkArtist'],

  query(contribs) {
    const associatedContributionsByOtherArtists =
      contribs
        .flatMap(ownContrib =>
          ownContrib.associatedContributions
            .filter(associatedContrib =>
              associatedContrib.artist !== ownContrib.artist));

    const otherArtists =
      unique(
        associatedContributionsByOtherArtists
          .map(contrib => contrib.artist));

    return {otherArtists};
  },

  relations: (relation, query) => ({
    artistLinks:
      query.otherArtists
        .map(artist => relation('linkArtist', artist)),
  }),

  generate: (relations) =>
    relations.artistLinks,
};