add user role
This commit is contained in:
@@ -3,6 +3,7 @@ package service
|
||||
import (
|
||||
"context"
|
||||
"eslogad-be/internal/logger"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"eslogad-be/internal/appcontext"
|
||||
@@ -134,7 +135,6 @@ func (s *LetterServiceImpl) CreateIncomingLetter(ctx context.Context, req *contr
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Send notifications to all recipients after successful creation
|
||||
if s.notificationProcessor != nil && len(recipients) > 0 {
|
||||
go s.sendLetterNotifications(context.Background(), result, recipients)
|
||||
}
|
||||
@@ -239,19 +239,15 @@ func (s *LetterServiceImpl) addCreatorAsRecipient(ctx context.Context, letterID
|
||||
|
||||
func (s *LetterServiceImpl) sendLetterNotifications(ctx context.Context, letter *contract.IncomingLetterResponse, recipients []entities.LetterIncomingRecipient) {
|
||||
for _, recipient := range recipients {
|
||||
// Only send notification to user recipients (not department recipients)
|
||||
// Also exclude the creator from receiving notifications
|
||||
if recipient.RecipientUserID != nil && *recipient.RecipientUserID != letter.CreatedBy {
|
||||
// Use description if available, otherwise use subject
|
||||
if recipient.Status != "completed" {
|
||||
err := s.notificationProcessor.SendIncomingLetterNotification(
|
||||
ctx,
|
||||
letter.ID,
|
||||
*recipient.RecipientUserID,
|
||||
"Surat Masuk",
|
||||
letter.Subject)
|
||||
fmt.Sprintf("%s: %s", letter.SenderInstitution.Name, letter.Subject))
|
||||
|
||||
if err != nil {
|
||||
// Log error but don't fail the entire operation
|
||||
logger.FromContext(ctx).Error("failed to send notification", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user