pg_auth_services.go 1.8 KB
package domain_service

import (
	"github.com/tiptok/gocomm/xa/eda"
	"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction"
	"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log"
)

type PgAuthService struct {
	eda.EventCenterPublisher
	//transactionContext *transaction.TransactionContext
	manager *PgManagerAuthService
	partner *PgPartnerAuthService
}

func NewPgAuthService(ctx *transaction.TransactionContext) *PgAuthService {
	return &PgAuthService{
		manager: NewPgManagerAuthService(ctx),
		partner: NewPgPartnerAuthService(ctx),
	}
}

func (s *PgAuthService) ChangeUserPhone(userId int64, newPhone, oldPhone string) (err error) {
	errPartner := s.partner.ChangeUserPhone(userId, newPhone, oldPhone) // 合伙人修改手机号
	errManager := s.manager.ChangeUserPhone(userId, newPhone, oldPhone) // 高管修改手机号
	return errResolve(errPartner, errManager)
}
func (s *PgAuthService) ChangeUserPassword(userId int64, newPwd, oldPwd, phone string) (err error) {
	errPartner := s.partner.ChangeUserPassword(userId, newPwd, oldPwd, phone)
	errManager := s.manager.ChangeUserPassword(userId, newPwd, oldPwd, phone)
	return errResolve(errPartner, errManager)
}
func (s *PgAuthService) ResetUserPassword(userId int64, phone, password string) (err error) {
	errPartner := s.partner.ResetUserPassword(userId, phone, password)
	errManager := s.manager.ResetUserPassword(userId, phone, password)
	return errResolve(errPartner, errManager)
}

func errResolve(errPartner, errManager error) (err error) {
	if errPartner != nil {
		log.Error("partner:", errPartner)
	}
	if errManager != nil {
		log.Error("mannager:", errManager)
	}
	if errPartner != nil && errManager != nil {
		err = errPartner
		if err == errUserNotFound && errManager != errUserNotFound {
			err = errManager
		}
		return
	}
	return
}