Skip to content

Commit cc603e5

Browse files
committed
:spark: added subscription filter
1 parent d971760 commit cc603e5

File tree

6 files changed

+93
-18
lines changed

6 files changed

+93
-18
lines changed

packages/integrations/gei-stripe/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gei-stripe",
3-
"version": "0.4.5",
3+
"version": "0.4.6",
44
"description": "Automatically generated by graphql-editor-cli",
55
"main": "lib/index.js",
66
"scripts": {

packages/integrations/gei-stripe/schema.graphql

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type Query{
88
filter: ProductFilter
99
): ProductsPage
1010
subscriptions(
11-
filter: SubscriptionFilter!
11+
filter: SubscriptionFilter
1212
): [Subscription!]
1313
paymentIntents(
1414
filter: PaymentIntentFilter!
@@ -279,7 +279,15 @@ enum BankAccountHolderType {
279279
}
280280

281281
input SubscriptionFilter {
282-
customerId: String!
282+
id: String
283+
cancel_at_period_end: Boolean
284+
current_period_end: TimestampFilter
285+
current_period_start: TimestampFilter
286+
customer: String
287+
description: String
288+
items: [String!]
289+
quantity: Int
290+
status: SubStatus
283291
}
284292

285293
type Subscription {
@@ -289,7 +297,7 @@ type Subscription {
289297
current_period_start: Timestamp!
290298
customer: String!
291299
description: String
292-
items:SubscriptionItems!
300+
items: SubscriptionItems!
293301
quantity: Int!
294302
status: SubStatus!
295303
}
Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,41 @@
11
import { FieldResolveInput } from 'stucco-js';
22
import { resolverFor } from '../zeus/index.js';
3-
import { MongoOrb } from "../db/orm.js";
3+
import { MongoOrb } from '../db/orm.js';
4+
import { timestampMapping } from '../utils/customTypes/types.js';
45

5-
export const handler = async (input: FieldResolveInput) =>
6+
export const handler = async (input: FieldResolveInput) =>
67
resolverFor('Query', 'subscriptions', async (args) => {
7-
const customerIdFilter = args?.filter?.customerId;
8-
9-
if (!customerIdFilter) {
10-
return await MongoOrb('StripeSubscriptionCollection').collection.find().toArray();
8+
let res;
9+
if (!args.filter) {
10+
res = await MongoOrb('StripeSubscriptionCollection').collection.find().toArray();
1111
} else {
12-
const filter = { customer: customerIdFilter };
12+
let filter: any = {};
13+
if (args.filter.id) filter.id = args.filter.id;
14+
if (args.filter.cancel_at_period_end !== undefined)
15+
filter.cancel_at_period_end = args.filter.cancel_at_period_end;
16+
if (args.filter.current_period_end) {
17+
filter.current_period_end = {};
18+
if (args.filter.current_period_end.Gt) filter.current_period_end.$gt = args.filter.current_period_end.Gt;
19+
if (args.filter.current_period_end.Gte) filter.current_period_end.$gte = args.filter.current_period_end.Gte;
20+
if (args.filter.current_period_end.Lt) filter.current_period_end.$lt = args.filter.current_period_end.Lt;
21+
if (args.filter.current_period_end.Lte) filter.current_period_end.$lte = args.filter.current_period_end.Lte;
22+
}
23+
if (args.filter.current_period_start) {
24+
filter.current_period_start = {};
25+
if (args.filter.current_period_start.Gt) filter.current_period_start.$gt = args.filter.current_period_start.Gt;
26+
if (args.filter.current_period_start.Gte)
27+
filter.current_period_start.$gte = args.filter.current_period_start.Gte;
28+
if (args.filter.current_period_start.Lt) filter.current_period_start.$lt = args.filter.current_period_start.Lt;
29+
if (args.filter.current_period_start.Lte)
30+
filter.current_period_start.$lte = args.filter.current_period_start.Lte;
31+
}
32+
33+
if (args.filter.customer) filter.customer = args.filter.customer;
34+
if (args.filter.description) filter.description = args.filter.description;
35+
if (args.filter.quantity) filter.quantity = args.filter.quantity;
36+
if (args.filter.status) filter.status = args.filter.status;
37+
if (args.filter.items) filter.items.data.id = { $in: args.filter.items };
1338
return await MongoOrb('StripeSubscriptionCollection').collection.find(filter).toArray();
1439
}
40+
return res;
1541
})(input.arguments);

packages/integrations/gei-stripe/src/utils/customTypes/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,10 @@ export type applicationFee = {
1616
feePercentage: number;
1717
connectAccountId: string;
1818
};
19+
20+
export const timestampMapping: { [key: string]: string } = {
21+
'Gt': '$gt',
22+
'Gte': '$gte',
23+
'Lt': '$lt',
24+
'Lte': '$lte'
25+
};

packages/integrations/gei-stripe/src/zeus/const.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ export const AllTypesProps: Record<string,any> = {
7575
},
7676
BankAccountHolderType: "enum" as const,
7777
SubscriptionFilter:{
78-
78+
current_period_end:"TimestampFilter",
79+
current_period_start:"TimestampFilter",
80+
status:"SubStatus"
7981
},
8082
SubStatus: "enum" as const,
8183
InitStripeCustomerInput:{

packages/integrations/gei-stripe/src/zeus/index.ts

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ type ZEUS_UNIONS = never
837837
export type ValueTypes = {
838838
["Query"]: AliasType<{
839839
products?: [{ filter?: ValueTypes["ProductFilter"] | undefined | null | Variable<any, string>},ValueTypes["ProductsPage"]],
840-
subscriptions?: [{ filter: ValueTypes["SubscriptionFilter"] | Variable<any, string>},ValueTypes["Subscription"]],
840+
subscriptions?: [{ filter?: ValueTypes["SubscriptionFilter"] | undefined | null | Variable<any, string>},ValueTypes["Subscription"]],
841841
paymentIntents?: [{ filter: ValueTypes["PaymentIntentFilter"] | Variable<any, string>},ValueTypes["PaymentIntent"]],
842842
invoices?: [{ filter: ValueTypes["InvoiceFilter"] | Variable<any, string>},ValueTypes["Invoice"]],
843843
customer?: [{ customerId: string | Variable<any, string>},ValueTypes["Customer"]],
@@ -980,7 +980,15 @@ createPayoutForConnectedAccount?: [{ payload: ValueTypes["createPayoutForConnect
980980
};
981981
["BankAccountHolderType"]:BankAccountHolderType;
982982
["SubscriptionFilter"]: {
983-
customerId: string | Variable<any, string>
983+
id?: string | undefined | null | Variable<any, string>,
984+
cancel_at_period_end?: boolean | undefined | null | Variable<any, string>,
985+
current_period_end?: ValueTypes["TimestampFilter"] | undefined | null | Variable<any, string>,
986+
current_period_start?: ValueTypes["TimestampFilter"] | undefined | null | Variable<any, string>,
987+
customer?: string | undefined | null | Variable<any, string>,
988+
description?: string | undefined | null | Variable<any, string>,
989+
items?: Array<string> | undefined | null | Variable<any, string>,
990+
quantity?: number | undefined | null | Variable<any, string>,
991+
status?: ValueTypes["SubStatus"] | undefined | null | Variable<any, string>
984992
};
985993
["Subscription"]: AliasType<{
986994
id?:boolean | `@${string}`,
@@ -1257,7 +1265,7 @@ createPayoutForConnectedAccount?: [{ payload: ValueTypes["createPayoutForConnect
12571265
export type ResolverInputTypes = {
12581266
["Query"]: AliasType<{
12591267
products?: [{ filter?: ResolverInputTypes["ProductFilter"] | undefined | null},ResolverInputTypes["ProductsPage"]],
1260-
subscriptions?: [{ filter: ResolverInputTypes["SubscriptionFilter"]},ResolverInputTypes["Subscription"]],
1268+
subscriptions?: [{ filter?: ResolverInputTypes["SubscriptionFilter"] | undefined | null},ResolverInputTypes["Subscription"]],
12611269
paymentIntents?: [{ filter: ResolverInputTypes["PaymentIntentFilter"]},ResolverInputTypes["PaymentIntent"]],
12621270
invoices?: [{ filter: ResolverInputTypes["InvoiceFilter"]},ResolverInputTypes["Invoice"]],
12631271
customer?: [{ customerId: string},ResolverInputTypes["Customer"]],
@@ -1400,7 +1408,15 @@ createPayoutForConnectedAccount?: [{ payload: ResolverInputTypes["createPayoutFo
14001408
};
14011409
["BankAccountHolderType"]:BankAccountHolderType;
14021410
["SubscriptionFilter"]: {
1403-
customerId: string
1411+
id?: string | undefined | null,
1412+
cancel_at_period_end?: boolean | undefined | null,
1413+
current_period_end?: ResolverInputTypes["TimestampFilter"] | undefined | null,
1414+
current_period_start?: ResolverInputTypes["TimestampFilter"] | undefined | null,
1415+
customer?: string | undefined | null,
1416+
description?: string | undefined | null,
1417+
items?: Array<string> | undefined | null,
1418+
quantity?: number | undefined | null,
1419+
status?: ResolverInputTypes["SubStatus"] | undefined | null
14041420
};
14051421
["Subscription"]: AliasType<{
14061422
id?:boolean | `@${string}`,
@@ -1821,7 +1837,15 @@ export type ModelTypes = {
18211837
};
18221838
["BankAccountHolderType"]:BankAccountHolderType;
18231839
["SubscriptionFilter"]: {
1824-
customerId: string
1840+
id?: string | undefined,
1841+
cancel_at_period_end?: boolean | undefined,
1842+
current_period_end?: ModelTypes["TimestampFilter"] | undefined,
1843+
current_period_start?: ModelTypes["TimestampFilter"] | undefined,
1844+
customer?: string | undefined,
1845+
description?: string | undefined,
1846+
items?: Array<string> | undefined,
1847+
quantity?: number | undefined,
1848+
status?: ModelTypes["SubStatus"] | undefined
18251849
};
18261850
["Subscription"]: {
18271851
id: string,
@@ -2228,7 +2252,15 @@ export type GraphQLTypes = {
22282252
};
22292253
["BankAccountHolderType"]: BankAccountHolderType;
22302254
["SubscriptionFilter"]: {
2231-
customerId: string
2255+
id?: string | undefined,
2256+
cancel_at_period_end?: boolean | undefined,
2257+
current_period_end?: GraphQLTypes["TimestampFilter"] | undefined,
2258+
current_period_start?: GraphQLTypes["TimestampFilter"] | undefined,
2259+
customer?: string | undefined,
2260+
description?: string | undefined,
2261+
items?: Array<string> | undefined,
2262+
quantity?: number | undefined,
2263+
status?: GraphQLTypes["SubStatus"] | undefined
22322264
};
22332265
["Subscription"]: {
22342266
__typename: "Subscription",

0 commit comments

Comments
 (0)