Skip to content

Commit eebe660

Browse files
feat(condo): DOMA-13327 make types
feat(condo): DOMA-13327 added tests feat(condo): DOMA-13327 added tests feat(condo): DOMA-13327 added tests
1 parent e01030f commit eebe660

3 files changed

Lines changed: 16 additions & 16 deletions

File tree

apps/condo/domains/subscription/schema/ActivateSubscriptionContextService.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ const { SubscriptionContext } = require('@condo/domains/subscription/utils/serve
2020

2121
const logger = getLogger('ActivateSubscriptionContextService')
2222

23-
const SUBSCRIPTION_ACTIVATED_WEBHOOK_URL = conf['SUBSCRIPTION_ACTIVATED_WEBHOOK_URL']
24-
const SUBSCRIPTION_ACTIVATED_WEBHOOK_SECRET = conf['SUBSCRIPTION_ACTIVATED_WEBHOOK_SECRET']
25-
2623
/**
2724
* List of possible errors, that this custom schema can throw
2825
* They will be rendered in documentation section in GraphiQL for this custom schema
@@ -176,20 +173,21 @@ const ActivateSubscriptionContextService = new GQLCustomSchema('ActivateSubscrip
176173
frozenPaymentInfo,
177174
})
178175

179-
if (SUBSCRIPTION_ACTIVATED_WEBHOOK_URL && SUBSCRIPTION_ACTIVATED_WEBHOOK_SECRET) {
176+
const webhookUrl = conf['SUBSCRIPTION_ACTIVATED_WEBHOOK_URL']
177+
const webhookSecret = conf['SUBSCRIPTION_ACTIVATED_WEBHOOK_SECRET']
178+
if (webhookUrl && webhookSecret) {
180179
try {
181180
const { keystone: internalContext } = getSchemaCtx('WebhookPayload')
182181
const payerOrg = await getById('Organization', invoice.payerOrganization)
183-
const createdByUser = await getById('User', invoice.createdBy)
184182
if (!payerOrg) {
185183
throw new Error(`Organization not found: ${invoice.payerOrganization}`)
186184
}
187-
if (!createdByUser) {
188-
throw new Error(`User not found: ${invoice.createdBy}`)
189-
}
185+
const createdByUser = invoice.createdBy
186+
? await getById('User', invoice.createdBy)
187+
: null
190188
await queueWebhookPayload(internalContext, {
191-
url: SUBSCRIPTION_ACTIVATED_WEBHOOK_URL,
192-
secret: SUBSCRIPTION_ACTIVATED_WEBHOOK_SECRET,
189+
url: webhookUrl,
190+
secret: webhookSecret,
193191
eventType: WEBHOOK_EVENT_SUBSCRIPTION_ACTIVATED,
194192
modelName: 'SubscriptionContext',
195193
itemId: subscriptionContext.id,
@@ -203,10 +201,12 @@ const ActivateSubscriptionContextService = new GQLCustomSchema('ActivateSubscrip
203201
name: payerOrg.name,
204202
tin: payerOrg.tin,
205203
},
206-
user: {
207-
id: createdByUser.id,
208-
name: createdByUser.name,
209-
},
204+
...(createdByUser && {
205+
user: {
206+
id: createdByUser.id,
207+
name: createdByUser.name,
208+
},
209+
}),
210210
},
211211
sender: { dv: 1, fingerprint: 'activateSubscriptionContext' },
212212
})

apps/condo/schema.graphql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91911,7 +91911,7 @@ type WebhookPayload {
9191191911
"""
9191291912
secret: String
9191391913

91914-
""" Type of event that triggered this webhook. Custom events: payment.status.updated. Auto-generated events from models with webHooked() plugin: ModelName.created, ModelName.updated, ModelName.deleted (e.g., Payment.created, Ticket.updated).
91914+
""" Type of event that triggered this webhook. Custom events: payment.status.updated, subscription.activated. Auto-generated events from models with webHooked() plugin: ModelName.created, ModelName.updated, ModelName.deleted (e.g., Payment.created, Ticket.updated).
9191591915
"""
9191691916
eventType: String
9191791917

apps/condo/schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120089,7 +120089,7 @@ export type WebhookPayload = {
120089120089
deletedAt?: Maybe<Scalars['String']['output']>;
120090120090
/** Data structure Version */
120091120091
dv?: Maybe<Scalars['Int']['output']>;
120092-
/** Type of event that triggered this webhook. Custom events: payment.status.updated. Auto-generated events from models with webHooked() plugin: ModelName.created, ModelName.updated, ModelName.deleted (e.g., Payment.created, Ticket.updated). */
120092+
/** Type of event that triggered this webhook. Custom events: payment.status.updated, subscription.activated. Auto-generated events from models with webHooked() plugin: ModelName.created, ModelName.updated, ModelName.deleted (e.g., Payment.created, Ticket.updated). */
120093120093
eventType?: Maybe<Scalars['String']['output']>;
120094120094
/** Timestamp after which no more send attempts will be made */
120095120095
expiresAt?: Maybe<Scalars['String']['output']>;

0 commit comments

Comments
 (0)