@@ -2,7 +2,6 @@ import { Injectable } from '@nestjs/common';
22import { NotificationsRepository } from '@gitroom/nestjs-libraries/database/prisma/notifications/notifications.repository' ;
33import { EmailService } from '@gitroom/nestjs-libraries/services/email.service' ;
44import { OrganizationRepository } from '@gitroom/nestjs-libraries/database/prisma/organizations/organization.repository' ;
5- import { ioRedis } from '@gitroom/nestjs-libraries/redis/redis.service' ;
65import { TemporalService } from 'nestjs-temporal-core' ;
76import { TypedSearchAttributes } from '@temporalio/common' ;
87import { organizationId } from '@gitroom/nestjs-libraries/temporal/temporal.search.attribute' ;
@@ -32,13 +31,6 @@ export class NotificationService {
3231 ) ;
3332 }
3433
35- getNotificationsSince ( organizationId : string , since : string ) {
36- return this . _notificationRepository . getNotificationsSince (
37- organizationId ,
38- since
39- ) ;
40- }
41-
4234 async inAppNotification (
4335 orgId : string ,
4436 subject : string ,
@@ -56,8 +48,18 @@ export class NotificationService {
5648 try {
5749 await this . _temporalService . client
5850 . getRawClient ( )
59- ?. workflow . start ( 'digestEmailWorkflow' , {
51+ ?. workflow . signalWithStart ( 'digestEmailWorkflow' , {
6052 workflowId : 'digest_email_workflow_' + orgId ,
53+ signal : 'email' ,
54+ signalArgs : [
55+ [
56+ {
57+ title : subject ,
58+ message,
59+ type,
60+ } ,
61+ ] ,
62+ ] ,
6163 taskQueue : 'main' ,
6264 args : [ { organizationId : orgId } ] ,
6365 typedSearchAttributes : new TypedSearchAttributes ( [
@@ -69,20 +71,6 @@ export class NotificationService {
6971 } ) ;
7072 } catch ( err ) { }
7173
72- await this . _temporalService . signalWorkflow (
73- 'digest_email_workflow_' + orgId ,
74- 'email' ,
75- [
76- [
77- {
78- title : subject ,
79- message,
80- type,
81- } ,
82- ] ,
83- ]
84- ) ;
85-
8674 return ;
8775 }
8876
@@ -111,45 +99,6 @@ export class NotificationService {
11199 }
112100 }
113101
114- async getDigestTypes ( orgId : string ) : Promise < NotificationType [ ] > {
115- const typesKey = 'digest_types_' + orgId ;
116- const types = await ioRedis . smembers ( typesKey ) ;
117- // Clean up the types key after reading
118- await ioRedis . del ( typesKey ) ;
119- return types as NotificationType [ ] ;
120- }
121-
122- async sendDigestEmailsToOrg (
123- orgId : string ,
124- subject : string ,
125- message : string ,
126- types : NotificationType [ ]
127- ) {
128- const userOrg = await this . _organizationRepository . getAllUsersOrgs ( orgId ) ;
129- const hasInfo = types . includes ( 'info' ) ;
130- const hasSuccess = types . includes ( 'success' ) ;
131- const hasFail = types . includes ( 'fail' ) ;
132-
133- for ( const user of userOrg ?. users || [ ] ) {
134- // 'info' type is always sent regardless of preferences
135- if ( hasInfo ) {
136- await this . sendEmail ( user . user . email , subject , message ) ;
137- continue ;
138- }
139-
140- // For digest, check if user wants any of the notification types in the digest
141- const wantsSuccess = hasSuccess && user . user . sendSuccessEmails ;
142- const wantsFail = hasFail && user . user . sendFailureEmails ;
143-
144- // Only send if user wants at least one type of notification in the digest
145- if ( ! wantsSuccess && ! wantsFail ) {
146- continue ;
147- }
148-
149- await this . sendEmail ( user . user . email , subject , message ) ;
150- }
151- }
152-
153102 async sendEmail ( to : string , subject : string , html : string , replyTo ?: string ) {
154103 await this . _emailService . sendEmail ( to , subject , html , replyTo ) ;
155104 }
0 commit comments