@@ -11,16 +11,17 @@ import {
1111} from 'graphql' ;
1212import { GraphQLDateTime } from 'graphql-scalars' ;
1313import { isNil , omit } from 'lodash' ;
14- import { OrderItem , QueryTypes } from 'sequelize' ;
14+ import { OrderItem , QueryTypes , WhereOptions } from 'sequelize' ;
1515
1616import PlatformConstants from '../../../constants/platform' ;
1717import { filterContributors } from '../../../lib/contributors' ;
1818import models , { Collective , sequelize } from '../../../models' ;
19+ import Tier , { AllTierTypes , TierType } from '../../../models/Tier' ;
1920import { checkReceiveFinancialContributions } from '../../common/features' ;
2021import { GraphQLAccountCollection } from '../collection/AccountCollection' ;
2122import { GraphQLContributorCollection } from '../collection/ContributorCollection' ;
2223import { GraphQLTierCollection } from '../collection/TierCollection' ;
23- import { GraphQLAccountType , GraphQLMemberRole } from '../enum' ;
24+ import { GraphQLAccountType , GraphQLMemberRole , GraphQLTierType } from '../enum' ;
2425
2526import { CollectionArgs } from './Collection' ;
2627
@@ -58,22 +59,56 @@ export const AccountWithContributionsFields = {
5859 description : 'The number of results to fetch' ,
5960 defaultValue : 100 ,
6061 } ,
62+ onlyValid : {
63+ type : GraphQLBoolean ,
64+ description :
65+ 'When true (default), exclude tiers with types that are no longer supported (e.g. taxable tiers when disabled by host). Use false for edit pages to show all tiers.' ,
66+ defaultValue : true ,
67+ } ,
6168 } ,
62- async resolve ( account : Collective , args : Record < string , unknown > ) : Promise < Record < string , unknown > > {
69+ async resolve (
70+ account : Collective ,
71+ args : Record < string , unknown > ,
72+ req : express . Request ,
73+ ) : Promise < Record < string , unknown > > {
6374 if ( ! account . hasBudget ( ) ) {
6475 return { nodes : [ ] , totalCount : 0 } ;
6576 }
6677
67- const query = {
68- where : { CollectiveId : account . id } ,
78+ const where : WhereOptions < Tier > = { CollectiveId : account . id } ;
79+ if ( args . onlyValid !== false ) {
80+ const host = await req . loaders . Collective . host . load ( account ) ;
81+ if ( Tier . hostHasDisabledTaxableTiers ( host ) ) {
82+ const validTypes = AllTierTypes . filter ( type => ! models . Tier . isForbiddenTaxableTierType ( account , host , type ) ) ;
83+ if ( validTypes . length !== AllTierTypes . length ) {
84+ where . type = validTypes ;
85+ }
86+ }
87+ }
88+
89+ const result = await models . Tier . findAndCountAll ( {
90+ where,
6991 order : [ [ 'amount' , 'ASC' ] ] as OrderItem [ ] ,
7092 limit : < number > args . limit ,
7193 offset : < number > args . offset ,
72- } ;
73- const result = await models . Tier . findAndCountAll ( query ) ;
94+ } ) ;
95+
7496 return { nodes : result . rows , totalCount : result . count , limit : args . limit , offset : args . offset } ;
7597 } ,
7698 } ,
99+ supportedTierTypes : {
100+ type : new GraphQLNonNull ( new GraphQLList ( new GraphQLNonNull ( GraphQLTierType ) ) ) ,
101+ description :
102+ 'Tier types that can be created for this account. Uses host tax settings and account overrides via Tier.isForbiddenTaxableTierType.' ,
103+ async resolve ( account : Collective , _ , req : express . Request ) : Promise < readonly TierType [ ] > {
104+ const host = await req . loaders . Collective . host . load ( account ) ;
105+ if ( Tier . hostHasDisabledTaxableTiers ( host ) ) {
106+ return AllTierTypes . filter ( tierType => ! models . Tier . isForbiddenTaxableTierType ( account , host , tierType ) ) ;
107+ } else {
108+ return AllTierTypes ;
109+ }
110+ } ,
111+ } ,
77112 contributors : {
78113 type : new GraphQLNonNull ( GraphQLContributorCollection ) ,
79114 description : 'All the persons and entities that contribute to this account' ,
0 commit comments