-
-
Notifications
You must be signed in to change notification settings - Fork 293
Expand file tree
/
Copy pathtypes.js
More file actions
1890 lines (1845 loc) · 55.2 KB
/
types.js
File metadata and controls
1890 lines (1845 loc) · 55.2 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import {
GraphQLBoolean,
GraphQLEnumType,
GraphQLError,
GraphQLFloat,
GraphQLInt,
GraphQLList,
GraphQLNonNull,
GraphQLObjectType,
GraphQLScalarType,
GraphQLString,
} from 'graphql';
import { Kind } from 'graphql/language';
import { GraphQLJSON } from 'graphql-scalars';
import { omit, pick } from 'lodash';
import moment from 'moment';
import FEATURE from '../../constants/feature';
import INTERVALS from '../../constants/intervals';
import { maxInteger } from '../../constants/math';
import orderStatus from '../../constants/order-status';
import { PAYMENT_METHOD_TYPE } from '../../constants/paymentMethods';
import roles from '../../constants/roles';
import { getCollectiveAvatarUrl } from '../../lib/collectivelib';
import { filterContributors } from '../../lib/contributors';
import { sanitizeStripeError } from '../../lib/stripe';
import twoFactorAuthLib from '../../lib/two-factor-authentication';
import models, { Op, sequelize } from '../../models';
import { PayoutMethodTypes } from '../../models/PayoutMethod';
import { canSeeExpenseAttachments, canSeeExpensePayoutMethodPrivateDetails } from '../common/expenses';
import { hasSeenLatestChangelogEntry } from '../common/user';
import { Unauthorized } from '../errors';
import { idEncode, IDENTIFIER_TYPES } from '../v2/identifiers';
import { CollectiveInterfaceType, CollectiveSearchResultsType } from './CollectiveInterface';
import { TransactionInterfaceType } from './TransactionInterface';
/**
* Take a graphql type and return a wrapper type that adds pagination. The pagination
* object has limit, offset and total keys to manage pages and stores the result
* of the query under the `values` key.
*
* @param {object} GraphQL type to paginate
* @param {string} The name of the type, used to generate name and description.
*/
const paginatedList = (type, typeName, valuesKey = 'nodes') => {
return new GraphQLObjectType({
name: `Paginated${typeName}`,
description: `A list of ${typeName} with pagination info`,
fields: {
[valuesKey]: { type: new GraphQLList(type) },
total: { type: GraphQLInt },
limit: { type: GraphQLInt },
offset: { type: GraphQLInt },
},
});
};
export const DateString = new GraphQLScalarType({
name: 'DateString',
serialize: value => {
return value.toString();
},
});
const IsoDateString = new GraphQLScalarType({
name: 'IsoDateString',
serialize: value => {
return value;
},
parseValue: value => {
return value;
},
parseLiteral: ast => {
if (ast.kind !== Kind.STRING) {
throw new GraphQLError(`Query error: Can only parse strings got a: ${ast.kind}`);
}
const date = moment.parseZone(ast.value);
if (!date.isValid()) {
throw new GraphQLError('Query error: unable to pass date string. Expected a valid ISO-8601 date string.');
}
return date;
},
});
const PayoutMethodTypeEnum = new GraphQLEnumType({
name: 'PayoutMethodTypeEnum',
values: Object.keys(PayoutMethodTypes).reduce((values, key) => {
return { ...values, [key]: { value: PayoutMethodTypes[key] } };
}, {}),
});
// @deprecated Still used in Collective.payoutMethods by `expenseFormPayeeStepCollectivePickerSearchQuery`
export const PayoutMethodType = new GraphQLObjectType({
name: 'PayoutMethod',
description: 'A payout method for expenses',
fields: () => ({
id: {
type: GraphQLInt,
},
type: {
type: PayoutMethodTypeEnum,
},
name: {
type: GraphQLString,
},
isSaved: {
type: GraphQLBoolean,
},
data: {
type: GraphQLJSON,
},
}),
});
export const UserType = new GraphQLObjectType({
name: 'UserDetails',
description: 'This represents the details of a User',
fields: () => {
return {
id: {
type: GraphQLInt,
resolve(user) {
return user.id;
},
},
CollectiveId: {
type: GraphQLInt,
resolve(user) {
return user.CollectiveId;
},
},
collective: {
type: CollectiveInterfaceType,
resolve(user, args, req) {
if (!user.CollectiveId) {
return null;
}
return req.loaders.Collective.byId.load(user.CollectiveId);
},
},
name: {
type: GraphQLString,
deprecationReason: '2022-06-02: Please use collective.name',
resolve(user) {
return user.name;
},
},
image: {
type: GraphQLString,
resolve(user) {
return user.image;
},
},
email: {
type: GraphQLString,
async resolve(user, args, req) {
if (
req.remoteUser &&
user.CollectiveId && // We sometimes pass an empty object as `user`
(await req.loaders.Collective.canSeePrivateProfileInfo.load(user.CollectiveId))
) {
return user.email;
}
},
},
emailWaitingForValidation: {
type: GraphQLString,
async resolve(user, args, req) {
if (
req.remoteUser &&
user.CollectiveId && // We sometimes pass an empty object as `user`
req.remoteUser.isAdmin(user.CollectiveId)
) {
return user.emailWaitingForValidation;
}
},
},
memberOf: {
type: new GraphQLList(MemberType),
args: {
roles: { type: new GraphQLList(GraphQLString) },
includeIncognito: {
type: GraphQLBoolean,
defaultValue: true,
description:
'Whether incognito profiles should be included in the result. Only works if requesting user is an admin of the account.',
},
},
resolve(user, args, req) {
const where = { MemberCollectiveId: user.CollectiveId };
if (args.roles && args.roles.length > 0) {
where.role = { [Op.in]: args.roles };
}
const collectiveConditions = {};
if (!args.includeIncognito || !req.remoteUser?.isAdmin(user.CollectiveId)) {
collectiveConditions.isIncognito = false;
}
return models.Member.findAll({
where,
include: [
{
model: models.Collective,
as: 'collective',
required: true,
where: collectiveConditions,
},
],
});
},
},
isLimited: {
type: GraphQLBoolean,
description: "Returns true if user account is limited (user can't use any feature)",
resolve(user) {
return user.data && user.data.features && user.data.features[FEATURE.ALL] === false;
},
},
hasSeenLatestChangelogEntry: {
type: GraphQLBoolean,
async resolve(user, args, req) {
if (req.remoteUser?.id !== user.id) {
return null;
}
return hasSeenLatestChangelogEntry(user);
},
},
hasTwoFactorAuth: {
type: GraphQLBoolean,
resolve(user, _, req) {
if (req.remoteUser?.id === user.id) {
return twoFactorAuthLib.userHasTwoFactorAuthEnabled(user);
}
},
},
hasPassword: {
type: GraphQLBoolean,
description: 'Has the account a password set?',
async resolve(user, args, req) {
if (req.remoteUser?.id === user.id) {
return Boolean(user.passwordHash);
}
},
},
requiresProfileCompletion: {
type: GraphQLBoolean,
async resolve(user, _, req) {
if (req.remoteUser?.id === user.id) {
const account = await req.loaders.Collective.byId.load(user.CollectiveId);
return Boolean(account.data?.requiresProfileCompletion);
}
},
},
isRoot: {
type: new GraphQLNonNull(GraphQLBoolean),
resolve(user) {
return user.isRoot();
},
},
};
},
});
const StatsMemberType = new GraphQLObjectType({
name: 'StatsMemberType',
description: 'Stats about a membership',
fields: () => {
return {
// We always have to return an id for apollo's caching (key: __typename+id)
id: {
type: GraphQLInt,
resolve(member) {
return member.id;
},
},
directDonations: {
type: GraphQLFloat,
description: 'total amount donated directly by this member',
resolve(member, args, req) {
return (
member.directDonations ||
req.loaders.Transaction.directDonationsFromTo.load({
FromCollectiveId: member.MemberCollectiveId,
CollectiveId: member.CollectiveId,
})
);
},
},
totalDonations: {
type: GraphQLFloat,
description: 'total amount donated by this member either directly or using a gift card it has emitted',
resolve(member, args, req) {
return (
member.totalDonations ||
req.loaders.Transaction.totalAmountDonatedFromTo.load({
FromCollectiveId: member.MemberCollectiveId,
CollectiveId: member.CollectiveId,
})
);
},
},
};
},
});
export const MemberType = new GraphQLObjectType({
name: 'Member',
description: 'This is a Member',
fields: () => {
return {
id: {
type: GraphQLInt,
resolve(member) {
return member.id;
},
},
createdAt: {
type: DateString,
resolve(member) {
return member.createdAt;
},
},
orders: {
type: new GraphQLList(OrderType),
args: {
limit: { type: GraphQLInt },
offset: { type: GraphQLInt },
},
resolve(member, args, req) {
return req.loaders.Order.findByMembership
.load(`${member.CollectiveId}:${member.MemberCollectiveId}`)
.then(orders => {
const { limit, offset } = args;
if (limit) {
return orders.splice(offset || 0, limit);
} else {
return orders;
}
});
},
},
transactions: {
type: new GraphQLList(TransactionInterfaceType),
args: {
limit: { type: GraphQLInt },
offset: { type: GraphQLInt },
},
resolve(member, args, req) {
return req.loaders.Member.transactions
.load(`${member.CollectiveId}:${member.MemberCollectiveId}`)
.then(transactions => {
/**
* xdamman: note: we can't pass a limit to the loader
* because the limit would be applied to the entire result set
* that includes the transactions from other members
* Given that the number of transaction for a given member to a given collective
* is expected to always be < 100, the tradeoff is in favor of using the DataLoader
*/
const { limit, offset } = args;
if (limit) {
return transactions.splice(offset || 0, limit);
} else {
return transactions;
}
});
},
},
collective: {
type: CollectiveInterfaceType,
async resolve(member, args, req) {
const collective = member.collective || (await req.loaders.Collective.byId.load(member.CollectiveId));
if (!collective?.isIncognito || req.remoteUser?.isAdmin(collective.id)) {
return collective;
}
},
},
member: {
type: CollectiveInterfaceType,
async resolve(member, args, req) {
const collective = member.collective || (await req.loaders.Collective.byId.load(member.CollectiveId));
if (collective?.isIncognito) {
if (!req.remoteUser?.isAdminOfCollective(collective)) {
return null;
}
}
return member.memberCollective || (await req.loaders.Collective.byId.load(member.MemberCollectiveId));
},
},
role: {
type: GraphQLString,
resolve(member) {
return member.role;
},
},
description: {
type: GraphQLString,
resolve(member) {
return member.description;
},
},
publicMessage: {
description: 'Custom user message from member to the collective',
type: GraphQLString,
resolve(member) {
return member.publicMessage;
},
},
tier: {
type: TierType,
resolve(member, args, req) {
return member.TierId && req.loaders.Tier.byId.load(member.TierId);
},
},
stats: {
type: StatsMemberType,
resolve(member) {
return member;
},
},
since: {
type: DateString,
resolve(member) {
return member.since;
},
},
isActive: {
type: new GraphQLNonNull(GraphQLBoolean),
description: 'Whether the membership is active. Warning: this definition is subject to change.',
async resolve(member, _, req) {
return req.loaders.Member.isActive.load(member.id);
},
},
};
},
});
export const ContributorRoleEnum = new GraphQLEnumType({
name: 'ContributorRole',
description: 'Possible roles for a contributor. Extends `Member.Role`.',
values: Object.values(roles).reduce((values, key) => {
return { ...values, [key]: {} };
}, {}),
});
export const ImageFormatType = new GraphQLEnumType({
name: 'ImageFormat',
values: {
txt: {},
png: {},
jpg: {},
gif: {},
svg: {},
},
});
export const ContributorType = new GraphQLObjectType({
name: 'Contributor',
description: `
A person or an entity that contributes financially or by any other mean to the mission
of the collective. While "Member" is dedicated to permissions, this type is meant
to surface all the public contributors.
`,
fields: () => ({
id: {
type: new GraphQLNonNull(GraphQLString),
description: 'A unique identifier for this member',
},
name: {
type: new GraphQLNonNull(GraphQLString),
description: 'Name of the contributor',
},
roles: {
type: new GraphQLList(ContributorRoleEnum),
description: 'All the roles for a given contributor',
defaultValue: [roles.CONTRIBUTOR],
},
isAdmin: {
type: new GraphQLNonNull(GraphQLBoolean),
description: 'True if the contributor is a collective admin',
},
isCore: {
type: new GraphQLNonNull(GraphQLBoolean),
description: 'True if the contributor is a core contributor',
},
isBacker: {
type: new GraphQLNonNull(GraphQLBoolean),
description: 'True if the contributor is a financial contributor',
},
tiersIds: {
type: new GraphQLNonNull(new GraphQLList(GraphQLInt)),
description:
'A list of tier ids that this contributors is a member of. A null value indicates that a membership without tier.',
},
since: {
type: new GraphQLNonNull(IsoDateString),
description: 'Member join date',
},
totalAmountDonated: {
type: new GraphQLNonNull(GraphQLInt),
description: 'How much money the user has contributed for this (in cents, using collective currency)',
},
type: {
type: new GraphQLNonNull(GraphQLString),
description: 'Whether the contributor is an individual, an organization...',
},
isIncognito: {
type: new GraphQLNonNull(GraphQLBoolean),
description: 'Defines if the contributors wants to be incognito (name not displayed)',
},
isGuest: {
type: new GraphQLNonNull(GraphQLBoolean),
description: 'Defines if the contributors is a guest account',
},
description: {
type: GraphQLString,
description: 'Description of how the member contribute. Will usually be a tier name, or "design" or "code".',
},
collectiveSlug: {
type: GraphQLString,
description: 'If the contributor has a page on Open Collective, this is the slug to link to it',
resolve(contributor) {
// Don't return the collective slug if the contributor wants to be incognito
return contributor.isIncognito ? null : contributor.collectiveSlug;
},
},
collectiveId: {
type: GraphQLInt,
description: 'Null for incognito collectives otherwise collective id',
resolve(contributor) {
// Don't return the collective id if the contributor wants to be incognito
return contributor.isIncognito ? null : contributor.id;
},
},
image: {
type: GraphQLString,
description: 'Contributor avatar or logo',
args: {
height: { type: GraphQLInt },
format: { type: ImageFormatType },
},
resolve(contributor, args) {
if (!contributor.collectiveSlug) {
return null;
} else {
return getCollectiveAvatarUrl(contributor.collectiveSlug, contributor.type, contributor.image, args);
}
},
},
publicMessage: {
type: GraphQLString,
description: 'A public message from contributors to describe their contributions',
},
}),
});
export const LocationType = new GraphQLObjectType({
name: 'LocationType',
description: 'Type for Location',
fields: () => ({
id: {
type: GraphQLString,
description: 'Unique identifier for this location',
},
name: {
type: GraphQLString,
description: 'A short name for the location (eg. Open Collective Headquarters)',
},
country: {
type: GraphQLString,
description: 'Two letters country code (eg. FR, BE...etc)',
},
lat: {
type: GraphQLFloat,
description: 'Latitude',
},
long: {
type: GraphQLFloat,
description: 'Longitude',
},
address: {
type: GraphQLString,
description: 'Postal address without country (eg. 12 opensource avenue, 7500 Paris)',
},
structured: {
type: GraphQLJSON,
description: 'Structured JSON address',
},
}),
});
export const InvoiceType = new GraphQLObjectType({
name: 'InvoiceType',
description: 'This represents an Invoice',
fields: () => {
return {
slug: {
type: GraphQLString,
resolve(invoice) {
return invoice.slug;
},
},
dateFrom: {
type: IsoDateString,
description:
'dateFrom and dateTo will be set for any invoice over a period of time. They will not be set for an invoice for a single transaction.',
resolve: invoice => invoice.dateFrom,
},
dateTo: {
type: IsoDateString,
description:
'dateFrom and dateTo will be set for any invoice over a period of time. They will not be set for an invoice for a single transaction.',
resolve: invoice => invoice.dateTo,
},
year: {
type: GraphQLInt,
description: 'year will be set for an invoice for a single transaction. Otherwise, prefer dateFrom, dateTo',
resolve(invoice) {
return invoice.year;
},
},
month: {
type: GraphQLInt,
description: 'month will be set for an invoice for a single transaction. Otherwise, prefer dateFrom, dateTo',
resolve(invoice) {
return invoice.month;
},
},
day: {
type: GraphQLInt,
description: 'day will be set for an invoice for a single transaction. Otherwise, prefer dateFrom, dateTo',
resolve(invoice) {
return invoice.day;
},
},
totalAmount: {
type: GraphQLInt,
deprecationReason: '2021-09-09: Not used, so we stop computing it.',
resolve(invoice) {
return invoice.totalAmount;
},
},
totalTransactions: {
type: GraphQLFloat,
resolve(invoice) {
return invoice.totalTransactions;
},
},
currency: {
type: GraphQLString,
deprecationReason: '2021-09-09: Not used, so we stop returning it.',
resolve(invoice) {
return invoice.currency;
},
},
host: {
type: CollectiveInterfaceType,
resolve(invoice, args, req) {
return req.loaders.Collective.byId.load(invoice.HostCollectiveId);
},
},
fromCollective: {
type: CollectiveInterfaceType,
async resolve(invoice, args, req) {
return req.loaders.Collective.byId.load(invoice.FromCollectiveId);
},
},
transactions: {
type: new GraphQLList(TransactionInterfaceType),
async resolve(invoice) {
// Directly return transactions if already loaded
if (invoice.transactions) {
return invoice.transactions;
}
const where = {
[Op.or]: {
FromCollectiveId: invoice.FromCollectiveId,
UsingGiftCardFromCollectiveId: invoice.FromCollectiveId,
},
type: 'CREDIT',
createdAt: { [Op.gte]: invoice.dateFrom, [Op.lt]: invoice.dateTo },
};
if (invoice.HostCollectiveId) {
where.HostCollectiveId = invoice.HostCollectiveId;
}
const transactions = await models.Transaction.findAll({ where });
return transactions;
},
},
};
},
});
const ExpenseItemType = new GraphQLObjectType({
name: 'ExpenseItem',
description: 'Public fields for an expense item',
deprecationReason: '2024-12-13: Please move to GraphQL v2',
fields: () => ({
id: { type: new GraphQLNonNull(GraphQLInt) },
amount: { type: new GraphQLNonNull(GraphQLInt) },
createdAt: { type: new GraphQLNonNull(IsoDateString) },
updatedAt: { type: new GraphQLNonNull(IsoDateString) },
incurredAt: { type: new GraphQLNonNull(IsoDateString) },
deletedAt: { type: IsoDateString },
description: { type: GraphQLString },
url: { type: GraphQLString },
}),
});
const ExpenseAttachedFile = new GraphQLObjectType({
name: 'ExpenseAttachedFile',
description: "Fields for an expense's attached file",
deprecationReason: '2024-12-13: Please move to GraphQL v2',
fields: () => ({
id: {
type: new GraphQLNonNull(GraphQLInt),
description: 'Unique identifier for this file',
},
url: {
type: GraphQLString,
},
}),
});
export const ExpenseType = new GraphQLObjectType({
name: 'ExpenseType',
description: 'This represents an Expense',
deprecationReason: '2024-12-13: Please move to GraphQL v2',
fields: () => {
return {
id: {
type: GraphQLInt,
resolve(expense) {
return expense.id;
},
},
idV2: {
type: GraphQLString,
resolve(expense) {
return idEncode(expense.id, IDENTIFIER_TYPES.EXPENSE);
},
},
amount: {
type: GraphQLFloat,
resolve(expense) {
return expense.amount;
},
},
currency: {
type: GraphQLString,
resolve(expense) {
return expense.currency;
},
},
createdAt: {
type: DateString,
resolve(expense) {
return expense.createdAt;
},
},
updatedAt: {
type: DateString,
resolve(expense) {
return expense.updatedAt;
},
},
incurredAt: {
type: DateString,
resolve(expense) {
return expense.incurredAt;
},
},
description: {
type: GraphQLString,
resolve(expense) {
return expense.description;
},
},
tags: {
type: new GraphQLList(GraphQLString),
resolve(expense) {
return expense.tags;
},
},
status: {
type: GraphQLString,
resolve(expense) {
return expense.status;
},
},
type: {
type: GraphQLString,
resolve(expense) {
return expense.type;
},
},
PayoutMethod: {
type: PayoutMethodType,
deprecationReason: '2024-12-13: Please move to GraphQL v2',
async resolve(expense, _, req) {
if (!expense.PayoutMethodId || !(await canSeeExpensePayoutMethodPrivateDetails(req, expense))) {
return null;
} else {
return expense.payoutMethod || req.loaders.PayoutMethod.byId.load(expense.PayoutMethodId);
}
},
},
privateMessage: {
type: GraphQLString,
async resolve(expense, args, req) {
if (!req.remoteUser) {
return null;
}
const collective = await req.loaders.Collective.byId.load(expense.CollectiveId);
if (req.remoteUser.isAdminOfCollective(collective) || req.remoteUser.id === expense.UserId) {
return expense.privateMessage;
} else if (req.remoteUser.isAdmin(collective.HostCollectiveId)) {
return expense.privateMessage;
} else {
return null;
}
},
},
items: {
type: new GraphQLList(ExpenseItemType),
deprecationReason: '2024-12-13: Please move to GraphQL v2',
async resolve(expense, _, req) {
const canSeeAttachments = await canSeeExpenseAttachments(req, expense);
return (await req.loaders.Expense.items.load(expense.id)).map(async item => {
if (canSeeAttachments) {
return item;
} else {
return omit(item, ['url']);
}
});
},
},
attachedFiles: {
type: new GraphQLList(new GraphQLNonNull(ExpenseAttachedFile)),
async resolve(expense, _, req) {
if (await canSeeExpenseAttachments(req, expense)) {
return req.loaders.Expense.attachedFiles.load(expense.id);
}
},
},
user: {
type: UserType,
async resolve(expense, _, req) {
return req.loaders.User.byId.load(expense.UserId);
},
},
fromCollective: {
type: CollectiveInterfaceType,
resolve(expense, _, req) {
return req.loaders.Collective.byId.load(expense.FromCollectiveId);
},
},
collective: {
type: CollectiveInterfaceType,
resolve(expense, args, req) {
return req.loaders.Collective.byId.load(expense.CollectiveId);
},
},
transaction: {
type: TransactionInterfaceType,
description: 'Returns the DEBIT transaction to pay out this expense',
resolve(expense) {
return models.Transaction.findOne({
where: {
type: 'DEBIT',
CollectiveId: expense.CollectiveId,
ExpenseId: expense.id,
},
});
},
},
};
},
});
export const NotificationType = new GraphQLObjectType({
name: 'NotificationType',
description: 'This represents a Notification',
deprecationReason: '2026-03-31: Please move to GraphQL v2',
fields: () => {
return {
id: {
type: GraphQLInt,
resolve(notification) {
return notification.id;
},
},
channel: {
description: 'channel to send notification',
type: GraphQLString,
resolve(notification) {
return notification.channel;
},
},
type: {
description: 'the notification type',
type: GraphQLString,
resolve(notification) {
return notification.type;
},
},
active: {
description: 'whether or not the notification is active',
type: GraphQLBoolean,
resolve(notification) {
return notification.active;
},
},
webhookUrl: {
type: GraphQLString,
resolve(notification) {
return notification.webhookUrl;
},
},
user: {
type: UserType,
resolve(notification) {
return notification.getUser();
},
},
collective: {
type: CollectiveInterfaceType,
resolve(notification, args, req) {
return req.loaders.Collective.byId.load(notification.CollectiveId);
},
},
createdAt: {
type: DateString,
resolve(comment) {
return comment.createdAt;
},
},
updatedAt: {
type: DateString,
resolve(comment) {
return comment.updatedAt;
},
},
};
},
});
const ContributorsStatsType = new GraphQLObjectType({
name: 'ContributorsStats',
description: 'Breakdown of contributors per type (ANY/USER/ORGANIZATION/COLLECTIVE)',
fields: () => {
return {
id: {
type: new GraphQLNonNull(GraphQLString),
description: "We always have to return an id for apollo's caching",
},
all: {
type: GraphQLInt,
description: 'Total number of contributors',
},
users: {
type: GraphQLInt,
description: 'Number of individuals',
resolve(stats) {
return stats.USER;
},
},
organizations: {
type: GraphQLInt,
description: 'Number of organizations',
resolve(stats) {
return stats.ORGANIZATION;
},
},
collectives: {
type: GraphQLInt,
description: 'Number of collectives',
resolve(stats) {
return stats.COLLECTIVE;
},
},
};
},
});
const TierStatsType = new GraphQLObjectType({
name: 'TierStatsType',
description: 'Stats about a tier',
fields: () => {
return {
// We always have to return an id for apollo's caching
id: {
type: GraphQLInt,
resolve(tier) {