@@ -18,6 +18,7 @@ import { Document } from '../../../entities/Document';
1818import { Context } from '../../../interfaces/Context' ;
1919import { DocumentTransformer } from '../../../utils/DocumentTransformer' ;
2020import { getUniqueHashId } from '../../../utils/getUniqueHashId' ;
21+ import { processWebhooks } from '../../../utils/processWebhooks' ;
2122import { DocumentRepository } from '../repositories/DocumentRepository' ;
2223import { SchemaFieldRepository } from '../repositories/SchemaFieldRepository' ;
2324import { SchemaRepository } from '../repositories/SchemaRepository' ;
@@ -186,18 +187,18 @@ export class DocumentResolver {
186187 @Arg ( 'locale' , { nullable : true } ) locale ?: string ,
187188 @Arg ( 'releaseId' , type => ID , { nullable : true } ) releaseId ?: string
188189 ) : Promise < boolean > {
189- const doc = await this . Document ( id , locale , releaseId ) ;
190+ const document = await this . Document ( id , locale , releaseId ) ;
190191 await this . documentRepository . update (
191192 {
192- documentId : doc . documentId ,
193+ documentId : document . documentId ,
193194 ...( locale && { locale } ) ,
194195 ...( releaseId && { releaseId } ) ,
195196 } ,
196197 {
197198 deletedAt : new Date ( ) ,
198199 }
199200 ) ;
200- // @todo run webhook
201+ processWebhooks ( 'document.removed' , { document } ) ;
201202 // @todo update algolia
202203 return true ;
203204 }
@@ -209,10 +210,11 @@ export class DocumentResolver {
209210 @Ctx ( ) context : Context //
210211 ) {
211212 const doc = await this . documentRepository . findOneOrFail ( { id, deletedAt : IsNull ( ) } ) ;
212- const result = this . documentRepository . publish ( doc , context . user . id ) ;
213- // @todo run webhook
213+ const publishedId = await this . documentRepository . publish ( doc , context . user . id ) ;
214+ const document = await this . Document ( publishedId ) ;
215+ processWebhooks ( 'document.published' , { document } ) ;
214216 // @todo update algolia
215- return result ;
217+ return document ;
216218 }
217219
218220 @Mutation ( returns => Document )
@@ -230,9 +232,10 @@ export class DocumentResolver {
230232 publishedAt : null as any ,
231233 }
232234 ) ;
233- // @todo run webhook
234235 // @todo update algolia
235- return this . Document ( id ) ;
236+ const document = await this . Document ( id ) ;
237+ processWebhooks ( 'document.unpublished' , { document } ) ;
238+ return document ;
236239 }
237240
238241 @FieldResolver ( returns => GraphQLJSON , { nullable : true } )
0 commit comments