-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.go
650 lines (541 loc) · 23.4 KB
/
service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
package database
import (
"context"
"log"
"github.com/savannahghi/enumutils"
"github.com/savannahghi/feedlib"
"github.com/savannahghi/firebasetools"
"github.com/savannahghi/onboarding/pkg/onboarding/application/dto"
"github.com/savannahghi/onboarding/pkg/onboarding/domain"
"github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/database/fb"
"github.com/savannahghi/profileutils"
)
// Repository interface that provide access to all persistent storage operations
type Repository interface {
UserProfileRepository
SupplierRepository
CustomerRepository
RolesRepository
// creates a user profile of using the provided phone number and uid
CreateUserProfile(
ctx context.Context,
phoneNumber, uid string,
) (*profileutils.UserProfile, error)
// creates a new user profile that is pre-filled using the provided phone number
CreateDetailedUserProfile(
ctx context.Context,
phoneNumber string,
profile profileutils.UserProfile,
) (*profileutils.UserProfile, error)
// fetches a user profile by uid
GetUserProfileByUID(
ctx context.Context,
uid string,
suspended bool,
) (*profileutils.UserProfile, error)
// fetches a user profile by id. returns the unsuspend profile
GetUserProfileByID(
ctx context.Context,
id string,
suspended bool,
) (*profileutils.UserProfile, error)
// fetches a user profile by phone number
GetUserProfileByPhoneNumber(
ctx context.Context,
phoneNumber string,
suspended bool,
) (*profileutils.UserProfile, error)
// fetches a user profile by primary phone number
GetUserProfileByPrimaryPhoneNumber(
ctx context.Context,
phoneNumber string,
suspend bool,
) (*profileutils.UserProfile, error)
// checks if a specific phone number has already been registered to another user
CheckIfPhoneNumberExists(ctx context.Context, phone string) (bool, error)
// checks if a specific email has already been registered to another user
CheckIfEmailExists(ctx context.Context, phone string) (bool, error)
// checks if a specific username has already been registered to another user
CheckIfUsernameExists(ctx context.Context, phone string) (bool, error)
GenerateAuthCredentialsForAnonymousUser(
ctx context.Context,
) (*profileutils.AuthCredentialResponse, error)
GenerateAuthCredentials(
ctx context.Context,
phone string,
profile *profileutils.UserProfile,
) (*profileutils.AuthCredentialResponse, error)
FetchAdminUsers(ctx context.Context) ([]*profileutils.UserProfile, error)
// removes user completely. This should be used only under testing environment
PurgeUserByPhoneNumber(ctx context.Context, phone string) error
HardResetSecondaryPhoneNumbers(
ctx context.Context,
profile *profileutils.UserProfile,
newSecondaryPhones []string,
) error
HardResetSecondaryEmailAddress(
ctx context.Context,
profile *profileutils.UserProfile,
newSecondaryEmails []string,
) error
// PINs
GetPINByProfileID(
ctx context.Context,
ProfileID string,
) (*domain.PIN, error)
// Record post visit survey
RecordPostVisitSurvey(
ctx context.Context,
input dto.PostVisitSurveyInput,
UID string,
) error
// User Pin methods
SavePIN(ctx context.Context, pin *domain.PIN) (bool, error)
UpdatePIN(ctx context.Context, id string, pin *domain.PIN) (bool, error)
ExchangeRefreshTokenForIDToken(
ctx context.Context,
token string,
) (*profileutils.AuthCredentialResponse, error)
GetOrCreatePhoneNumberUser(ctx context.Context, phone string) (*dto.CreatedUserResponse, error)
AddUserAsExperimentParticipant(
ctx context.Context,
profile *profileutils.UserProfile,
) (bool, error)
RemoveUserAsExperimentParticipant(
ctx context.Context,
profile *profileutils.UserProfile,
) (bool, error)
CheckIfExperimentParticipant(ctx context.Context, profileID string) (bool, error)
GetUserCommunicationsSettings(
ctx context.Context,
profileID string,
) (*profileutils.UserCommunicationsSetting, error)
SetUserCommunicationsSettings(ctx context.Context, profileID string,
allowWhatsApp *bool, allowTextSms *bool, allowPush *bool, allowEmail *bool) (*profileutils.UserCommunicationsSetting, error)
}
// SupplierRepository defines signatures that relate to suppliers
type SupplierRepository interface {
StageProfileNudge(ctx context.Context, nudge *feedlib.Nudge) error
CheckIfAdmin(profile *profileutils.UserProfile) bool
}
// CustomerRepository defines signatures that relate to customers
type CustomerRepository interface {
// GetUserProfileByPhoneOrEmail gets usser profile by phone or email
GetUserProfileByPhoneOrEmail(ctx context.Context, payload *dto.RetrieveUserProfileInput) (*profileutils.UserProfile, error)
// UpdateUserProfileEmail updates user profile's email
UpdateUserProfileEmail(ctx context.Context, phone string, email string) error
}
// UserProfileRepository interface that provide access to all persistent storage operations for user profile
type UserProfileRepository interface {
UpdateUserName(ctx context.Context, id string, userName string) error
UpdatePrimaryPhoneNumber(ctx context.Context, id string, phoneNumber string) error
UpdatePrimaryEmailAddress(ctx context.Context, id string, emailAddress string) error
UpdateSecondaryPhoneNumbers(ctx context.Context, id string, phoneNumbers []string) error
UpdateSecondaryEmailAddresses(ctx context.Context, id string, emailAddresses []string) error
UpdateVerifiedIdentifiers(
ctx context.Context,
id string,
identifiers []profileutils.VerifiedIdentifier,
) error
UpdateVerifiedUIDS(ctx context.Context, id string, uids []string) error
UpdateSuspended(ctx context.Context, id string, status bool) error
UpdatePhotoUploadID(ctx context.Context, id string, uploadID string) error
UpdateCovers(ctx context.Context, id string, covers []profileutils.Cover) error
UpdatePushTokens(ctx context.Context, id string, pushToken []string) error
UpdatePermissions(ctx context.Context, id string, perms []profileutils.PermissionType) error
UpdateRole(ctx context.Context, id string, role profileutils.RoleType) error
UpdateUserRoleIDs(ctx context.Context, id string, roleIDs []string) error
UpdateBioData(ctx context.Context, id string, data profileutils.BioData) error
UpdateAddresses(
ctx context.Context,
id string,
address profileutils.Address,
addressType enumutils.AddressType,
) error
UpdateFavNavActions(ctx context.Context, id string, favActions []string) error
ListUserProfiles(
ctx context.Context,
role profileutils.RoleType,
) ([]*profileutils.UserProfile, error)
}
//RolesRepository interface that provide access to all persistent storage operations for roles
type RolesRepository interface {
CreateRole(
ctx context.Context,
profileID string,
input dto.RoleInput,
) (*profileutils.Role, error)
GetAllRoles(ctx context.Context) (*[]profileutils.Role, error)
GetRoleByID(ctx context.Context, roleID string) (*profileutils.Role, error)
GetRoleByName(ctx context.Context, roleName string) (*profileutils.Role, error)
GetRolesByIDs(ctx context.Context, roleIDs []string) (*[]profileutils.Role, error)
CheckIfRoleNameExists(ctx context.Context, name string) (bool, error)
UpdateRoleDetails(ctx context.Context, profileID string, role profileutils.Role) (*profileutils.Role, error)
DeleteRole(ctx context.Context, roleID string) (bool, error)
CheckIfUserHasPermission(
ctx context.Context,
UID string,
requiredPermission profileutils.Permission,
) (bool, error)
// GetUserProfilesByRole retrieves userprofiles with a particular role
GetUserProfilesByRoleID(ctx context.Context, role string) ([]*profileutils.UserProfile, error)
SaveRoleRevocation(ctx context.Context, userID string, revocation dto.RoleRevocationInput) error
}
// DbService is an implementation of the database repository
// It is implementation agnostic i.e logic should be handled using
// the preferred database
type DbService struct {
firestore *fb.Repository
}
// NewDbService creates a new database service
func NewDbService() *DbService {
ctx := context.Background()
fc := &firebasetools.FirebaseClient{}
firebaseApp, err := fc.InitFirebase()
if err != nil {
return nil
}
fbc, err := firebaseApp.Auth(ctx)
if err != nil {
log.Panicf("can't initialize Firebase auth when setting up profile service: %s", err)
}
fsc, err := firebaseApp.Firestore(ctx)
if err != nil {
log.Fatalf("unable to initialize Firestore: %s", err)
}
firestoreExtension := fb.NewFirestoreClientExtension(fsc)
firestore := fb.NewFirebaseRepository(firestoreExtension, fbc)
return &DbService{
firestore: firestore,
}
}
// CheckPreconditions ensures correct initialization
func (d DbService) CheckPreconditions() {
if d.firestore == nil {
log.Panicf("nil firestore service in database service")
}
}
// StageProfileNudge stages nudges published from this service.
func (d DbService) StageProfileNudge(ctx context.Context, nudge *feedlib.Nudge) error {
return d.firestore.StageProfileNudge(ctx, nudge)
}
// CheckIfAdmin checks if a user has admin permissions
func (d DbService) CheckIfAdmin(profile *profileutils.UserProfile) bool {
return d.firestore.CheckIfAdmin(profile)
}
// UpdateUserName updates the username of a profile that matches the id
// this method should be called after asserting the username is unique and not associated with another userProfile
func (d DbService) UpdateUserName(ctx context.Context, id string, userName string) error {
return d.firestore.UpdateUserName(ctx, id, userName)
}
// UpdatePrimaryPhoneNumber append a new primary phone number to the user profile
// this method should be called after asserting the phone number is unique and not associated with another userProfile
func (d DbService) UpdatePrimaryPhoneNumber(ctx context.Context, id string, phoneNumber string) error {
return d.firestore.UpdatePrimaryPhoneNumber(ctx, id, phoneNumber)
}
// UpdatePrimaryEmailAddress the primary email addresses of the profile that matches the id
// this method should be called after asserting the emailAddress is unique and not associated with another userProfile
func (d DbService) UpdatePrimaryEmailAddress(ctx context.Context, id string, emailAddress string) error {
return d.firestore.UpdatePrimaryEmailAddress(ctx, id, emailAddress)
}
// UpdateSecondaryPhoneNumbers updates the secondary phone numbers of the profile that matches the id
// this method should be called after asserting the phone numbers are unique and not associated with another userProfile
func (d DbService) UpdateSecondaryPhoneNumbers(ctx context.Context, id string, phoneNumbers []string) error {
return d.firestore.UpdateSecondaryPhoneNumbers(ctx, id, phoneNumbers)
}
// UpdateSecondaryEmailAddresses the secondary email addresses of the profile that matches the id
// this method should be called after asserting the emailAddresses as unique and not associated with another userProfile
func (d DbService) UpdateSecondaryEmailAddresses(ctx context.Context, id string, emailAddresses []string) error {
return d.firestore.UpdateSecondaryEmailAddresses(ctx, id, emailAddresses)
}
// UpdateVerifiedIdentifiers adds a UID to a user profile during login if it does not exist
func (d DbService) UpdateVerifiedIdentifiers(
ctx context.Context,
id string,
identifiers []profileutils.VerifiedIdentifier,
) error {
return d.firestore.UpdateVerifiedIdentifiers(ctx, id, identifiers)
}
// UpdateVerifiedUIDS adds a UID to a user profile during login if it does not exist
func (d DbService) UpdateVerifiedUIDS(ctx context.Context, id string, uids []string) error {
return d.firestore.UpdateVerifiedUIDS(ctx, id, uids)
}
// UpdateSuspended updates the suspend attribute of the profile that matches the id
func (d DbService) UpdateSuspended(ctx context.Context, id string, status bool) error {
return d.firestore.UpdateSuspended(ctx, id, status)
}
// UpdatePhotoUploadID updates the photoUploadID attribute of the profile that matches the id
func (d DbService) UpdatePhotoUploadID(ctx context.Context, id string, uploadID string) error {
return d.firestore.UpdatePhotoUploadID(ctx, id, uploadID)
}
// UpdateCovers updates the covers attribute of the profile that matches the id
func (d DbService) UpdateCovers(ctx context.Context, id string, covers []profileutils.Cover) error {
return d.firestore.UpdateCovers(ctx, id, covers)
}
// UpdatePushTokens updates the pushTokens attribute of the profile that matches the id. This function does a hard reset instead of prior
// matching
func (d DbService) UpdatePushTokens(ctx context.Context, id string, pushToken []string) error {
return d.firestore.UpdatePushTokens(ctx, id, pushToken)
}
// UpdatePermissions update the permissions of the user profile
func (d DbService) UpdatePermissions(ctx context.Context, id string, perms []profileutils.PermissionType) error {
return d.firestore.UpdatePermissions(ctx, id, perms)
}
// UpdateRole update the permissions of the user profile
func (d DbService) UpdateRole(ctx context.Context, id string, role profileutils.RoleType) error {
return d.firestore.UpdateRole(ctx, id, role)
}
// UpdateUserRoleIDs updates the roles for a user
func (d DbService) UpdateUserRoleIDs(ctx context.Context, id string, roleIDs []string) error {
return d.firestore.UpdateUserRoleIDs(ctx, id, roleIDs)
}
// UpdateBioData updates the biodate of the profile that matches the id
func (d DbService) UpdateBioData(ctx context.Context, id string, data profileutils.BioData) error {
return d.firestore.UpdateBioData(ctx, id, data)
}
// UpdateAddresses persists a user's home or work address information to the database
func (d DbService) UpdateAddresses(
ctx context.Context,
id string,
address profileutils.Address,
addressType enumutils.AddressType,
) error {
return d.firestore.UpdateAddresses(ctx, id, address, addressType)
}
// UpdateFavNavActions update the permissions of the user profile
func (d DbService) UpdateFavNavActions(ctx context.Context, id string, favActions []string) error {
return d.firestore.UpdateFavNavActions(ctx, id, favActions)
}
// ListUserProfiles fetches all users with the specified role from the database
func (d DbService) ListUserProfiles(
ctx context.Context,
role profileutils.RoleType,
) ([]*profileutils.UserProfile, error) {
return d.firestore.ListUserProfiles(ctx, role)
}
// CreateRole creates a new role and persists it to the database
func (d DbService) CreateRole(
ctx context.Context,
profileID string,
input dto.RoleInput,
) (*profileutils.Role, error) {
return d.firestore.CreateRole(ctx, profileID, input)
}
// GetAllRoles returns a list of all created roles
func (d DbService) GetAllRoles(ctx context.Context) (*[]profileutils.Role, error) {
return d.firestore.GetAllRoles(ctx)
}
// GetRoleByID gets role with matching id
func (d DbService) GetRoleByID(ctx context.Context, roleID string) (*profileutils.Role, error) {
return d.firestore.GetRoleByID(ctx, roleID)
}
// GetRoleByName retrieves a role using it's name
func (d DbService) GetRoleByName(ctx context.Context, roleName string) (*profileutils.Role, error) {
return d.firestore.GetRoleByName(ctx, roleName)
}
// GetRolesByIDs gets all roles matching provided roleIDs if specified otherwise all roles
func (d DbService) GetRolesByIDs(ctx context.Context, roleIDs []string) (*[]profileutils.Role, error) {
return d.firestore.GetRolesByIDs(ctx, roleIDs)
}
// CheckIfRoleNameExists checks if a role with a similar name exists
// Ensures unique name for each role during creation
func (d DbService) CheckIfRoleNameExists(ctx context.Context, name string) (bool, error) {
return d.firestore.CheckIfRoleNameExists(ctx, name)
}
// UpdateRoleDetails updates the details of a role
func (d DbService) UpdateRoleDetails(ctx context.Context, profileID string, role profileutils.Role) (*profileutils.Role, error) {
return d.firestore.UpdateRoleDetails(ctx, profileID, role)
}
// DeleteRole removes a role permanently from the database
func (d DbService) DeleteRole(ctx context.Context, roleID string) (bool, error) {
return d.firestore.DeleteRole(ctx, roleID)
}
//CheckIfUserHasPermission checks if a user has the required permission
func (d DbService) CheckIfUserHasPermission(
ctx context.Context,
UID string,
requiredPermission profileutils.Permission,
) (bool, error) {
return d.firestore.CheckIfUserHasPermission(ctx, UID, requiredPermission)
}
// GetUserProfilesByRoleID returns a list of user profiles with the role ID
// i.e users assigned a particular role
func (d DbService) GetUserProfilesByRoleID(ctx context.Context, role string) ([]*profileutils.UserProfile, error) {
return d.firestore.GetUserProfilesByRoleID(ctx, role)
}
// CreateUserProfile creates a user profile of using the provided phone number and uid
func (d DbService) CreateUserProfile(
ctx context.Context,
phoneNumber, uid string,
) (*profileutils.UserProfile, error) {
return d.firestore.CreateUserProfile(ctx, phoneNumber, uid)
}
// CreateDetailedUserProfile creates a new user profile that is pre-filled using the provided phone number
func (d DbService) CreateDetailedUserProfile(
ctx context.Context,
phoneNumber string,
profile profileutils.UserProfile,
) (*profileutils.UserProfile, error) {
return d.firestore.CreateDetailedUserProfile(ctx, phoneNumber, profile)
}
// GetUserProfileByUID fetches a user profile by uid
func (d DbService) GetUserProfileByUID(
ctx context.Context,
uid string,
suspended bool,
) (*profileutils.UserProfile, error) {
return d.firestore.GetUserProfileByUID(ctx, uid, suspended)
}
// GetUserProfileByID fetches a user profile by id. returns the unsuspend profile
func (d DbService) GetUserProfileByID(
ctx context.Context,
id string,
suspended bool,
) (*profileutils.UserProfile, error) {
return d.firestore.GetUserProfileByID(ctx, id, suspended)
}
// GetUserProfileByPhoneNumber fetches a user profile by phone number
func (d DbService) GetUserProfileByPhoneNumber(
ctx context.Context,
phoneNumber string,
suspended bool,
) (*profileutils.UserProfile, error) {
return d.firestore.GetUserProfileByPhoneNumber(ctx, phoneNumber, suspended)
}
// GetUserProfileByPrimaryPhoneNumber fetches a user profile by primary phone number
func (d DbService) GetUserProfileByPrimaryPhoneNumber(
ctx context.Context,
phoneNumber string,
suspend bool,
) (*profileutils.UserProfile, error) {
return d.firestore.GetUserProfileByPrimaryPhoneNumber(ctx, phoneNumber, suspend)
}
// CheckIfPhoneNumberExists checks if a specific phone number has already been registered to another user
func (d DbService) CheckIfPhoneNumberExists(ctx context.Context, phone string) (bool, error) {
return d.firestore.CheckIfPhoneNumberExists(ctx, phone)
}
// CheckIfEmailExists checks if a specific email has already been registered to another user
func (d DbService) CheckIfEmailExists(ctx context.Context, email string) (bool, error) {
return d.firestore.CheckIfEmailExists(ctx, email)
}
// CheckIfUsernameExists checks if a specific username has already been registered to another user
func (d DbService) CheckIfUsernameExists(ctx context.Context, phone string) (bool, error) {
username := phone
return d.firestore.CheckIfUsernameExists(ctx, username)
}
// GenerateAuthCredentialsForAnonymousUser ...
func (d DbService) GenerateAuthCredentialsForAnonymousUser(
ctx context.Context,
) (*profileutils.AuthCredentialResponse, error) {
return d.firestore.GenerateAuthCredentialsForAnonymousUser(ctx)
}
// GenerateAuthCredentials ...
func (d DbService) GenerateAuthCredentials(
ctx context.Context,
phone string,
profile *profileutils.UserProfile,
) (*profileutils.AuthCredentialResponse, error) {
return d.firestore.GenerateAuthCredentials(ctx, phone, profile)
}
// FetchAdminUsers ...
func (d DbService) FetchAdminUsers(ctx context.Context) ([]*profileutils.UserProfile, error) {
return d.firestore.FetchAdminUsers(ctx)
}
// PurgeUserByPhoneNumber removes user completely. This should be used only under testing environment
func (d DbService) PurgeUserByPhoneNumber(ctx context.Context, phone string) error {
return d.firestore.PurgeUserByPhoneNumber(ctx, phone)
}
// HardResetSecondaryPhoneNumbers ...
func (d DbService) HardResetSecondaryPhoneNumbers(
ctx context.Context,
profile *profileutils.UserProfile,
newSecondaryPhones []string,
) error {
return d.firestore.HardResetSecondaryPhoneNumbers(ctx, profile, newSecondaryPhones)
}
// HardResetSecondaryEmailAddress ...
func (d DbService) HardResetSecondaryEmailAddress(
ctx context.Context,
profile *profileutils.UserProfile,
newSecondaryEmails []string,
) error {
return d.firestore.HardResetSecondaryEmailAddress(ctx, profile, newSecondaryEmails)
}
// GetPINByProfileID ...
func (d DbService) GetPINByProfileID(
ctx context.Context,
ProfileID string,
) (*domain.PIN, error) {
return d.firestore.GetPINByProfileID(ctx, ProfileID)
}
// RecordPostVisitSurvey records the post visit survey
func (d DbService) RecordPostVisitSurvey(
ctx context.Context,
input dto.PostVisitSurveyInput,
UID string,
) error {
return d.firestore.RecordPostVisitSurvey(ctx, input, UID)
}
// SavePIN User Pin methods
func (d DbService) SavePIN(ctx context.Context, pin *domain.PIN) (bool, error) {
return d.firestore.SavePIN(ctx, pin)
}
// UpdatePIN ...
func (d DbService) UpdatePIN(ctx context.Context, id string, pin *domain.PIN) (bool, error) {
return d.firestore.UpdatePIN(ctx, id, pin)
}
// ExchangeRefreshTokenForIDToken ...
func (d DbService) ExchangeRefreshTokenForIDToken(
ctx context.Context,
token string,
) (*profileutils.AuthCredentialResponse, error) {
return d.firestore.ExchangeRefreshTokenForIDToken(ctx, token)
}
// GetOrCreatePhoneNumberUser ...
func (d DbService) GetOrCreatePhoneNumberUser(ctx context.Context, phone string) (*dto.CreatedUserResponse, error) {
return d.firestore.GetOrCreatePhoneNumberUser(ctx, phone)
}
// AddUserAsExperimentParticipant ...
func (d DbService) AddUserAsExperimentParticipant(
ctx context.Context,
profile *profileutils.UserProfile,
) (bool, error) {
return d.firestore.AddUserAsExperimentParticipant(ctx, profile)
}
// RemoveUserAsExperimentParticipant ...
func (d DbService) RemoveUserAsExperimentParticipant(
ctx context.Context,
profile *profileutils.UserProfile,
) (bool, error) {
return d.firestore.RemoveUserAsExperimentParticipant(ctx, profile)
}
// CheckIfExperimentParticipant ...
func (d DbService) CheckIfExperimentParticipant(ctx context.Context, profileID string) (bool, error) {
return d.firestore.CheckIfExperimentParticipant(ctx, profileID)
}
// GetUserCommunicationsSettings ...
func (d DbService) GetUserCommunicationsSettings(
ctx context.Context,
profileID string,
) (*profileutils.UserCommunicationsSetting, error) {
return d.firestore.GetUserCommunicationsSettings(ctx, profileID)
}
// SetUserCommunicationsSettings ...
func (d DbService) SetUserCommunicationsSettings(ctx context.Context, profileID string,
allowWhatsApp *bool, allowTextSms *bool, allowPush *bool, allowEmail *bool) (*profileutils.UserCommunicationsSetting, error) {
return d.firestore.SetUserCommunicationsSettings(ctx, profileID, allowWhatsApp, allowTextSms, allowPush, allowEmail)
}
// SaveRoleRevocation records a log for a role revocation
//
// userId is the ID of the user removing a role from a user
func (d DbService) SaveRoleRevocation(ctx context.Context, userID string, revocation dto.RoleRevocationInput) error {
return d.firestore.SaveRoleRevocation(ctx, userID, revocation)
}
// GetUserProfileByPhoneOrEmail gets usser profile by phone or email
func (d DbService) GetUserProfileByPhoneOrEmail(ctx context.Context, payload *dto.RetrieveUserProfileInput) (*profileutils.UserProfile, error) {
return d.firestore.GetUserProfileByPhoneOrEmail(ctx, payload)
}
// UpdateUserProfileEmail updates user profile's email
func (d DbService) UpdateUserProfileEmail(ctx context.Context, phone string, email string) error {
return d.firestore.UpdateUserProfileEmail(ctx, phone, email)
}