@@ -80,7 +80,7 @@ export class NotificationTemplateRepository extends BaseRepository<
8080 environmentId : string ,
8181 identifier : string ,
8282 session ?: ClientSession | null ,
83- skipUpdatedBy : boolean = false
83+ includeUpdatedBy : boolean = true
8484 ) {
8585 const requestQuery : NotificationTemplateQuery = {
8686 _environmentId : environmentId ,
@@ -89,7 +89,7 @@ export class NotificationTemplateRepository extends BaseRepository<
8989
9090 const query = this . MongooseModel . findOne ( requestQuery , undefined , { session } ) . populate ( 'steps.template' ) ;
9191
92- if ( ! skipUpdatedBy ) {
92+ if ( includeUpdatedBy ) {
9393 query . populate ( 'updatedBy' ) ;
9494 }
9595
@@ -113,7 +113,7 @@ export class NotificationTemplateRepository extends BaseRepository<
113113 return this . mapEntities ( query ) ;
114114 }
115115
116- async findById ( id : string , environmentId : string , session ?: ClientSession | null ) {
116+ async findById ( id : string , environmentId : string , session ?: ClientSession | null , includeUpdatedBy : boolean = true ) {
117117 const query = this . MongooseModel . findOne (
118118 {
119119 _id : id ,
@@ -124,110 +124,129 @@ export class NotificationTemplateRepository extends BaseRepository<
124124 )
125125 . populate ( 'steps.template' )
126126 . populate ( 'steps.variants.template' )
127- . populate ( 'updatedBy' ) ;
128127
129- const item = await query ;
128+ if ( includeUpdatedBy ) {
129+ query . populate ( 'updatedBy' ) ;
130+ }
130131
131- return this . mapEntity ( item ) ;
132- }
132+ const item = await query ;
133133
134- async findByTriggerIdentifierAndUpdate ( environmentId : string , triggerIdentifier : string , lastTriggeredAt : Date ) {
135- const requestQuery : NotificationTemplateQuery = {
136- _environmentId : environmentId ,
137- 'triggers.identifier' : triggerIdentifier ,
138- } ;
134+ return this . mapEntity ( item ) ;
135+ }
139136
140- const item = await this . MongooseModel . findOneAndUpdate (
141- requestQuery ,
142- {
143- $set : {
144- lastTriggeredAt,
137+ async ;
138+ findByTriggerIdentifierAndUpdate ( environmentId : string , triggerIdentifier : string , lastTriggeredAt : Date )
139+ {
140+ const requestQuery : NotificationTemplateQuery = {
141+ _environmentId : environmentId ,
142+ 'triggers.identifier' : triggerIdentifier ,
143+ } ;
144+
145+ const item = await this . MongooseModel . findOneAndUpdate (
146+ requestQuery ,
147+ {
148+ $set : {
149+ lastTriggeredAt,
150+ } ,
145151 } ,
146- } ,
147- {
148- timestamps : false ,
149- }
150- ) . populate ( 'steps.template' ) ;
151-
152- return this . mapEntity ( item ) ;
153- }
152+ {
153+ timestamps : false ,
154+ }
155+ ) . populate ( 'steps.template' ) ;
154156
155- async updatePublishFields ( workflowId : string , environmentId : string , userId : string , session ?: ClientSession | null ) {
156- const requestQuery : NotificationTemplateQuery = {
157- _id : workflowId ,
158- _environmentId : environmentId ,
159- } ;
157+ return this . mapEntity ( item ) ;
158+ }
160159
161- const item = await this . MongooseModel . findOneAndUpdate (
162- requestQuery ,
163- {
164- $set : {
165- lastPublishedAt : new Date ( ) ,
166- _lastPublishedBy : userId ,
160+ async ;
161+ updatePublishFields ( workflowId : string , environmentId : string , userId : string , session ?: ClientSession | null )
162+ {
163+ const requestQuery : NotificationTemplateQuery = {
164+ _id : workflowId ,
165+ _environmentId : environmentId ,
166+ } ;
167+
168+ const item = await this . MongooseModel . findOneAndUpdate (
169+ requestQuery ,
170+ {
171+ $set : {
172+ lastPublishedAt : new Date ( ) ,
173+ _lastPublishedBy : userId ,
174+ } ,
167175 } ,
168- } ,
169- { session, new : true }
170- ) ;
176+ { session, new : true }
177+ ) ;
171178
172- return this . mapEntity ( item ) ;
173- }
179+ return this . mapEntity ( item ) ;
180+ }
174181
175- async findBlueprintById ( id : string ) {
176- if ( ! this . blueprintOrganizationId ) throw new DalException ( 'Blueprint environment id was not found' ) ;
182+ async ;
183+ findBlueprintById ( id : string )
184+ {
185+ if ( ! this . blueprintOrganizationId ) throw new DalException ( 'Blueprint environment id was not found' ) ;
177186
178- const requestQuery : NotificationTemplateQuery = {
179- isBlueprint : true ,
180- _organizationId : this . blueprintOrganizationId ,
181- _id : id ,
182- } ;
187+ const requestQuery : NotificationTemplateQuery = {
188+ isBlueprint : true ,
189+ _organizationId : this . blueprintOrganizationId ,
190+ _id : id ,
191+ } ;
183192
184- const item = await this . MongooseModel . findOne ( requestQuery )
185- . populate ( 'steps.template' )
186- . populate ( 'notificationGroup' )
187- . lean ( ) ;
193+ const item = await this . MongooseModel . findOne ( requestQuery )
194+ . populate ( 'steps.template' )
195+ . populate ( 'notificationGroup' )
196+ . lean ( ) ;
188197
189- return this . mapEntity ( item ) ;
190- }
198+ return this . mapEntity ( item ) ;
199+ }
191200
192- async findBlueprintByTriggerIdentifier ( identifier : string ) {
193- if ( ! this . blueprintOrganizationId ) throw new DalException ( 'Blueprint environment id was not found' ) ;
201+ async ;
202+ findBlueprintByTriggerIdentifier ( identifier : string )
203+ {
204+ if ( ! this . blueprintOrganizationId ) throw new DalException ( 'Blueprint environment id was not found' ) ;
194205
195- const requestQuery : NotificationTemplateQuery = {
196- isBlueprint : true ,
197- _organizationId : this . blueprintOrganizationId ,
198- triggers : { $elemMatch : { identifier } } ,
199- } ;
206+ const requestQuery : NotificationTemplateQuery = {
207+ isBlueprint : true ,
208+ _organizationId : this . blueprintOrganizationId ,
209+ triggers : { $elemMatch : { identifier } } ,
210+ } ;
200211
201- const item = await this . MongooseModel . findOne ( requestQuery )
202- . populate ( 'steps.template' )
203- . populate ( 'notificationGroup' )
204- . lean ( ) ;
212+ const item = await this . MongooseModel . findOne ( requestQuery )
213+ . populate ( 'steps.template' )
214+ . populate ( 'notificationGroup' )
215+ . lean ( ) ;
205216
206- return this . mapEntity ( item ) ;
207- }
217+ return this . mapEntity ( item ) ;
218+ }
208219
209- async findBlueprintTemplates ( organizationId : string , environmentId : string ) : Promise < NotificationTemplateEntity [ ] > {
210- const _organizationId = organizationId ;
220+ async ;
221+ findBlueprintTemplates ( organizationId : string , environmentId : string )
222+ : Promise < NotificationTemplateEntity [ ] >
223+ {
224+ const _organizationId = organizationId ;
211225
212- if ( ! _organizationId ) throw new DalException ( 'Blueprint environment id was not found' ) ;
226+ if ( ! _organizationId ) throw new DalException ( 'Blueprint environment id was not found' ) ;
213227
214- const templates = await this . MongooseModel . find ( {
215- isBlueprint : true ,
216- _environmentId : environmentId ,
217- _organizationId,
218- } )
219- . populate ( 'steps.template' )
220- . populate ( 'notificationGroup' )
221- . lean ( ) ;
228+ const templates = await this . MongooseModel . find ( {
229+ isBlueprint : true ,
230+ _environmentId : environmentId ,
231+ _organizationId,
232+ } )
233+ . populate ( 'steps.template' )
234+ . populate ( 'notificationGroup' )
235+ . lean ( ) ;
222236
223- if ( ! templates ) {
224- return [ ] ;
225- }
237+ if ( ! templates ) {
238+ return [ ] ;
239+ }
226240
227- return this . mapEntities ( templates ) ;
228- }
241+ return this . mapEntities ( templates ) ;
242+ }
229243
230- async findAllGroupedByCategory ( ) : Promise < { name : string ; blueprints : NotificationTemplateEntity [ ] } [ ] > {
244+ async ;
245+ findAllGroupedByCategory ( ) ;
246+ : Promise <
247+ name : string ;
248+ blueprints : NotificationTemplateEntity [ ]
249+ [ ] > {
231250 const organizationId = this . blueprintOrganizationId ;
232251
233252 if ( ! organizationId ) {
0 commit comments