bulk delete outgoing letter
This commit is contained in:
@@ -23,6 +23,7 @@ type LetterOutgoingProcessor interface {
|
||||
SearchOutgoingLetters(ctx context.Context, filters map[string]interface{}, page, limit int, sortBy, sortOrder string) ([]entities.LetterOutgoing, int64, error)
|
||||
UpdateOutgoingLetter(ctx context.Context, letter *entities.LetterOutgoing, userID uuid.UUID) error
|
||||
DeleteOutgoingLetter(ctx context.Context, id uuid.UUID, userID uuid.UUID) error
|
||||
BulkDeleteOutgoingLetters(ctx context.Context, ids []uuid.UUID, userID uuid.UUID) error
|
||||
|
||||
UpdateLetterStatus(ctx context.Context, letterID uuid.UUID, status entities.LetterOutgoingStatus, userID uuid.UUID, fromStatus, toStatus *string) error
|
||||
ArchiveOutgoingLetter(ctx context.Context, letterID uuid.UUID, userID uuid.UUID) error
|
||||
@@ -349,15 +350,42 @@ func (p *LetterOutgoingProcessorImpl) DeleteOutgoingLetter(ctx context.Context,
|
||||
return err
|
||||
}
|
||||
|
||||
letter, _ := p.letterRepo.Get(txCtx, id)
|
||||
activityLog := &entities.LetterOutgoingActivityLog{
|
||||
LetterID: letter.ID,
|
||||
LetterID: id,
|
||||
ActionType: entities.LetterOutgoingActionDeleted,
|
||||
ActorUserID: &userID,
|
||||
}
|
||||
|
||||
if err := p.activityLogRepo.Create(txCtx, activityLog); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (p *LetterOutgoingProcessorImpl) BulkDeleteOutgoingLetters(ctx context.Context, ids []uuid.UUID, userID uuid.UUID) error {
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return p.txManager.WithTransaction(ctx, func(txCtx context.Context) error {
|
||||
|
||||
// Create activity log untuk setiap letter yang dihapus
|
||||
for _, id := range ids {
|
||||
activityLog := &entities.LetterOutgoingActivityLog{
|
||||
LetterID: id,
|
||||
ActionType: entities.LetterOutgoingActionDeleted,
|
||||
ActorUserID: &userID,
|
||||
}
|
||||
if err := p.activityLogRepo.Create(txCtx, activityLog); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := p.letterRepo.BulkSoftDelete(txCtx, ids); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user