DeleteContact a user if exists as a contact
(ctx context.Context, email string)
| 40 | |
| 41 | // DeleteContact a user if exists as a contact |
| 42 | func (service *MarketingService) DeleteContact(ctx context.Context, email string) error { |
| 43 | ctx, span, ctxLogger := service.tracer.StartWithLogger(ctx, service.logger) |
| 44 | defer span.End() |
| 45 | |
| 46 | response, _, err := service.plunkClient.Contacts.List(ctx, map[string]string{"search": email}) |
| 47 | if err != nil { |
| 48 | return service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, fmt.Sprintf("cannot search for contact with email [%s]", email))) |
| 49 | } |
| 50 | |
| 51 | if len(response.Data) == 0 { |
| 52 | ctxLogger.Info(fmt.Sprintf("no contact found with email [%s], skipping deletion", email)) |
| 53 | return nil |
| 54 | } |
| 55 | |
| 56 | contact := response.Data[0] |
| 57 | if _, err = service.plunkClient.Contacts.Delete(ctx, contact.ID); err != nil { |
| 58 | return service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, fmt.Sprintf("cannot delete user with ID [%s] from contacts", contact.Data[string(semconv.EnduserIDKey)]))) |
| 59 | } |
| 60 | |
| 61 | ctxLogger.Info(fmt.Sprintf("deleted user with ID [%s] from as marketting contact with ID [%s]", contact.Data[string(semconv.EnduserIDKey)], contact.ID)) |
| 62 | return nil |
| 63 | } |
| 64 | |
| 65 | // CreateContact adds a new user on the onboarding automation. |
| 66 | func (service *MarketingService) CreateContact(ctx context.Context, userID entities.UserID) error { |
no test coverage detected