Skip to content

Commit

Permalink
refact: make accounts query compatible with v1/search query
Browse files Browse the repository at this point in the history
  • Loading branch information
kewitz committed Mar 5, 2024
1 parent 2c3efde commit 4fd3bb4
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions server/graphql/v2/query/collection/AccountsCollectionQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ export const CommonAccountsCollectionQueryArgs = {
type: GraphQLBoolean,
description: 'Included collectives which are archived',
},
skipGuests: {
type: GraphQLBoolean,
description: 'Included collectives which are archived',
defaultValue: true,
},
isActive: {
type: GraphQLBoolean,
description: 'Only return "active" accounts with Financial Contributions enabled if true.',
Expand All @@ -54,6 +59,10 @@ const AccountsCollectionQuery = {
type: new GraphQLList(GraphQLAccountReferenceInput),
description: 'Host hosting the account',
},
parent: {
type: new GraphQLList(GraphQLAccountReferenceInput),
description: 'Host hosting the account',
},
type: {
type: new GraphQLList(GraphQLAccountType),
description:
Expand Down Expand Up @@ -81,10 +90,8 @@ const AccountsCollectionQuery = {
const { offset, limit } = args;
const cleanTerm = args.searchTerm?.trim();

let hostCollectiveIds;
if (args.host) {
hostCollectiveIds = await fetchAccountsIdsWithReference(args.host);
}
const hostCollectiveIds = args.host && (await fetchAccountsIdsWithReference(args.host));
const parentCollectiveIds = args.parent && (await fetchAccountsIdsWithReference(args.parent));

const includeVendorsForHostId = args.includeVendorsForHost
? await fetchAccountWithReference(args.includeVendorsForHost).then(({ id }) => id)
Expand All @@ -93,11 +100,12 @@ const AccountsCollectionQuery = {
const extraParameters = {
orderBy: args.orderBy || { field: 'RANK', direction: 'DESC' },
types: args.type?.length ? args.type.map(value => AccountTypeToModelMapping[value]) : null,
hostCollectiveIds: hostCollectiveIds,
parentCollectiveIds: null,
hostCollectiveIds,
parentCollectiveIds,
isHost: args.isHost ? true : null,
onlyActive: args.isActive ? true : null,
skipRecentAccounts: args.skipRecentAccounts,
skipGuests: args.skipGuests,
hasCustomContributionsEnabled: args.hasCustomContributionsEnabled,
countries: args.country,
tags: args.tag,
Expand Down

0 comments on commit 4fd3bb4

Please sign in to comment.