update config
This commit is contained in:
@@ -15,10 +15,15 @@ type RegistrationService interface {
|
||||
ResendOTP(ctx mycontext.Context, token string) (*entity.ResendOTPResponse, error)
|
||||
}
|
||||
|
||||
type CryptoSvc interface {
|
||||
GenerateJWTCustomer(user *entity.Customer) (string, error)
|
||||
}
|
||||
|
||||
type memberSvc struct {
|
||||
repo Repository
|
||||
notification NotificationService
|
||||
customerSvc CustomerService
|
||||
crypt CryptoSvc
|
||||
}
|
||||
|
||||
type Repository interface {
|
||||
@@ -42,10 +47,12 @@ func NewMemberRegistrationService(
|
||||
repo Repository,
|
||||
notification NotificationService,
|
||||
customerSvc CustomerService,
|
||||
crypt CryptoSvc,
|
||||
) RegistrationService {
|
||||
return &memberSvc{
|
||||
repo: repo,
|
||||
notification: notification,
|
||||
customerSvc: customerSvc,
|
||||
crypt: crypt,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,11 +38,12 @@ func (s *memberSvc) InitiateRegistration(
|
||||
BirthDate: request.BirthDate,
|
||||
OTP: otp,
|
||||
Status: constants.RegistrationPending,
|
||||
ExpiresAt: constants.TimeNow().Add(10 * time.Minute), // OTP expires in 10 minutes
|
||||
ExpiresAt: constants.TimeNow().Add(10 * time.Minute),
|
||||
CreatedAt: constants.TimeNow(),
|
||||
UpdatedAt: constants.TimeNow(),
|
||||
BranchID: request.BranchID,
|
||||
CashierID: request.CashierID,
|
||||
Password: request.GetHashPassword(),
|
||||
}
|
||||
|
||||
savedRegistration, err := s.repo.CreateRegistration(ctx, registration)
|
||||
@@ -125,7 +126,14 @@ func (s *memberSvc) VerifyOTP(
|
||||
logger.ContextLogger(ctx).Warn("failed to send welcome email", zap.Error(err))
|
||||
}
|
||||
|
||||
signedToken, err := s.crypt.GenerateJWTCustomer(customer)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &entity.MemberVerificationResponse{
|
||||
Auth: customer.ToUserAuthenticate(signedToken),
|
||||
CustomerID: customer.ID,
|
||||
Name: customer.Name,
|
||||
Email: customer.Email,
|
||||
@@ -200,23 +208,23 @@ func (s *memberSvc) sendRegistrationOTP(
|
||||
ctx mycontext.Context,
|
||||
registration *entity.MemberRegistration,
|
||||
) error {
|
||||
emailData := map[string]interface{}{
|
||||
"UserName": registration.Name,
|
||||
"OTPCode": registration.OTP,
|
||||
}
|
||||
//emailData := map[string]interface{}{
|
||||
// "UserName": registration.Name,
|
||||
// "OTPCode": registration.OTP,
|
||||
//}
|
||||
|
||||
err := s.notification.SendEmailTransactional(ctx, entity.SendEmailNotificationParam{
|
||||
Sender: "noreply@enaklo.co.id",
|
||||
Recipient: registration.Email,
|
||||
Subject: "Enaklo - Registration Verification Code",
|
||||
TemplateName: "member_registration_otp",
|
||||
TemplatePath: "templates/member_registration_otp.html",
|
||||
Data: emailData,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
//err := s.notification.SendEmailTransactional(ctx, entity.SendEmailNotificationParam{
|
||||
// Sender: "noreply@enaklo.co.id",
|
||||
// Recipient: registration.Email,
|
||||
// Subject: "Enaklo - Registration Verification Code",
|
||||
// TemplateName: "member_registration_otp",
|
||||
// TemplatePath: "templates/member_registration_otp.html",
|
||||
// Data: emailData,
|
||||
//})
|
||||
//
|
||||
//if err != nil {
|
||||
// return err
|
||||
//}
|
||||
|
||||
//if registration.Phone != "" {
|
||||
// smsMessage := fmt.Sprintf("Your Enaklo registration code is: %s. Please provide this code to our staff to complete your registration.", registration.OTP)
|
||||
|
||||
@@ -76,7 +76,7 @@ func NewServiceManagerImpl(cfg *config.Config, repo *repository.RepoManagerImpl)
|
||||
Balance: balance.NewBalanceService(repo.Wallet, repo.Trx, repo.Crypto, &cfg.Withdraw, repo.Transaction),
|
||||
DiscoverService: discovery.NewDiscoveryService(repo.Site, cfg.Discovery, repo.Product),
|
||||
OrderV2Svc: orderSvc.New(repo.OrderRepo, productSvcV2, custSvcV2, repo.TransactionRepo, repo.Crypto, &cfg.Order, repo.EmailService, partnerSettings),
|
||||
MemberRegistrationSvc: member.NewMemberRegistrationService(repo.MemberRepository, repo.EmailService, custSvcV2),
|
||||
MemberRegistrationSvc: member.NewMemberRegistrationService(repo.MemberRepository, repo.EmailService, custSvcV2, repo.Crypto),
|
||||
CustomerV2Svc: custSvcV2,
|
||||
InProgressSvc: inprogressOrder,
|
||||
ProductV2Svc: productSvcV2,
|
||||
|
||||
@@ -94,7 +94,7 @@ func (s *customerSvc) ResolveCustomer(ctx mycontext.Context, req *entity.Custome
|
||||
return 0, errors.New("customer name is required to create a new customer")
|
||||
}
|
||||
|
||||
lastSeq, err := s.repo.FindSequence(ctx, *ctx.GetPartnerID())
|
||||
lastSeq, err := s.repo.FindSequence(ctx, 1)
|
||||
if err != nil {
|
||||
return 0, errors.New("failed to resolve customer sequence")
|
||||
}
|
||||
@@ -106,7 +106,7 @@ func (s *customerSvc) ResolveCustomer(ctx mycontext.Context, req *entity.Custome
|
||||
Points: 0,
|
||||
CreatedAt: constants.TimeNow(),
|
||||
UpdatedAt: constants.TimeNow(),
|
||||
CustomerID: utils.GenerateMemberID(ctx, *ctx.GetPartnerID(), lastSeq),
|
||||
CustomerID: utils.GenerateMemberID(ctx, 1, lastSeq),
|
||||
BirthDate: req.BirthDate,
|
||||
}
|
||||
|
||||
@@ -225,7 +225,7 @@ func (s *customerSvc) CustomerCheck(ctx mycontext.Context, req *entity.CustomerR
|
||||
return &entity.CustomerCheckResponse{
|
||||
Exists: true,
|
||||
Customer: customer,
|
||||
Message: "Customer already exists with this phone number",
|
||||
Message: "Nomor telepon sudah terdaftar. Silakan gunakan nomor lain atau login.",
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
@@ -244,7 +244,7 @@ func (s *customerSvc) CustomerCheck(ctx mycontext.Context, req *entity.CustomerR
|
||||
return &entity.CustomerCheckResponse{
|
||||
Exists: true,
|
||||
Customer: customer,
|
||||
Message: "Customer already exists with this email",
|
||||
Message: "Email sudah terdaftar. Silakan gunakan email lain atau login.",
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,9 @@ type Repository interface {
|
||||
ctx mycontext.Context,
|
||||
req entity.PopularProductsRequest,
|
||||
) ([]entity.PopularProductItem, error)
|
||||
GetOrderHistoryByUserID(ctx mycontext.Context, userID int64, req entity.SearchRequest) ([]*entity.Order, int64, error)
|
||||
FindByIDAndPartnerID(ctx mycontext.Context, id int64, partnerID int64) (*entity.Order, error)
|
||||
FindByIDAndCustomerID(ctx mycontext.Context, id int64, customerID int64) (*entity.Order, error)
|
||||
}
|
||||
|
||||
type ProductService interface {
|
||||
@@ -96,6 +99,8 @@ type Service interface {
|
||||
limit int,
|
||||
sortBy string,
|
||||
) ([]entity.PopularProductItem, error)
|
||||
GetCustomerOrderHistory(ctx mycontext.Context, userID int64, request entity.SearchRequest) ([]*entity.Order, int64, error)
|
||||
GetOrderByOrderAndCustomerID(ctx mycontext.Context, customerID int64, orderID int64) (*entity.Order, error)
|
||||
}
|
||||
|
||||
type Config interface {
|
||||
|
||||
@@ -1,10 +1,29 @@
|
||||
package order
|
||||
|
||||
import (
|
||||
"enaklo-pos-be/internal/common/logger"
|
||||
"enaklo-pos-be/internal/common/mycontext"
|
||||
"enaklo-pos-be/internal/entity"
|
||||
"github.com/pkg/errors"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func (s *orderSvc) GetOrderHistory(ctx mycontext.Context, partnerID int64, request entity.SearchRequest) ([]*entity.Order, int64, error) {
|
||||
return s.repo.GetOrderHistoryByPartnerID(ctx, partnerID, request)
|
||||
}
|
||||
|
||||
func (s *orderSvc) GetCustomerOrderHistory(ctx mycontext.Context, userID int64, request entity.SearchRequest) ([]*entity.Order, int64, error) {
|
||||
return s.repo.GetOrderHistoryByUserID(ctx, userID, request)
|
||||
}
|
||||
|
||||
func (s *orderSvc) GetOrderByOrderAndCustomerID(ctx mycontext.Context, customerID int64, orderID int64) (*entity.Order, error) {
|
||||
orders, err := s.repo.FindByIDAndCustomerID(ctx, orderID, customerID)
|
||||
if err != nil {
|
||||
logger.ContextLogger(ctx).Error("failed to get in-progress orders by partner ID",
|
||||
zap.Error(err),
|
||||
zap.Int64("customerID", customerID))
|
||||
return nil, errors.Wrap(err, "failed to get order")
|
||||
}
|
||||
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user