@@ -5,6 +5,7 @@ import { ProjectNotificationsRuleDBScheme } from '@hawk.so/types';
55import { ResolverContextWithUser } from '../types/graphql' ;
66import { ApolloError , UserInputError } from 'apollo-server-express' ;
77import { NotificationsChannelsDBScheme } from '../types/notification-channels' ;
8+ import { validateWebhookEndpoint } from '../utils/webhookEndpointValidator' ;
89
910/**
1011 * Mutation payload for creating notifications rule from GraphQL Schema
@@ -101,7 +102,7 @@ function validateNotificationsRuleTresholdAndPeriod(
101102/**
102103 * Return true if all passed channels are filled with correct endpoints
103104 */
104- function validateNotificationsRuleChannels ( channels : NotificationsChannelsDBScheme ) : string | null {
105+ async function validateNotificationsRuleChannels ( channels : NotificationsChannelsDBScheme ) : Promise < string | null > {
105106 if ( channels . email ! . isEnabled ) {
106107 if ( ! / ^ [ a - z A - Z 0 - 9 . _ % + - ] + @ [ a - z A - Z 0 - 9 . - ] + \. [ a - z A - Z ] { 2 , } $ / . test ( channels . email ! . endpoint ) ) {
107108 return 'Invalid email endpoint passed' ;
@@ -126,6 +127,14 @@ function validateNotificationsRuleChannels(channels: NotificationsChannelsDBSche
126127 }
127128 }
128129
130+ if ( channels . webhook ?. isEnabled ) {
131+ const webhookError = await validateWebhookEndpoint ( channels . webhook . endpoint ) ;
132+
133+ if ( webhookError !== null ) {
134+ return webhookError ;
135+ }
136+ }
137+
129138 return null ;
130139}
131140
@@ -152,7 +161,7 @@ export default {
152161 throw new ApolloError ( 'No project with such id' ) ;
153162 }
154163
155- const channelsValidationResult = validateNotificationsRuleChannels ( input . channels ) ;
164+ const channelsValidationResult = await validateNotificationsRuleChannels ( input . channels ) ;
156165
157166 if ( channelsValidationResult !== null ) {
158167 throw new UserInputError ( channelsValidationResult ) ;
@@ -190,7 +199,7 @@ export default {
190199 throw new ApolloError ( 'No project with such id' ) ;
191200 }
192201
193- const channelsValidationResult = validateNotificationsRuleChannels ( input . channels ) ;
202+ const channelsValidationResult = await validateNotificationsRuleChannels ( input . channels ) ;
194203
195204 if ( channelsValidationResult !== null ) {
196205 throw new UserInputError ( channelsValidationResult ) ;
0 commit comments