54 lines
1.6 KiB
Go
54 lines
1.6 KiB
Go
package user
|
|
|
|
import (
|
|
"Yimaru-Backend/internal/domain"
|
|
"context"
|
|
)
|
|
|
|
func (s *Service) CreateUser(ctx context.Context, User domain.CreateUserReq, is_company bool) (domain.User, error) {
|
|
// Create User
|
|
// creator, err := s.userStore.GetUserByID(ctx, createrUserId)
|
|
// if err != nil {
|
|
// return domain.User{}, err
|
|
// }
|
|
// if creator.Role != domain.RoleAdmin {
|
|
// User.BranchID = creator.BranchID
|
|
// User.Role = string(domain.RoleCashier)
|
|
// } else {
|
|
// User.BranchID = branchId
|
|
// User.Role = string(domain.RoleBranchManager)
|
|
// }
|
|
|
|
hashedPassword, err := hashPassword(User.Password)
|
|
if err != nil {
|
|
return domain.User{}, err
|
|
}
|
|
|
|
return s.userStore.CreateUserWithoutOtp(ctx, domain.User{
|
|
FirstName: User.FirstName,
|
|
LastName: User.LastName,
|
|
Email: User.Email,
|
|
PhoneNumber: User.PhoneNumber,
|
|
Password: hashedPassword,
|
|
Role: domain.Role(User.Role),
|
|
EmailVerified: true,
|
|
PhoneVerified: true,
|
|
Suspended: User.Suspended,
|
|
OrganizationID: User.OrganizationID,
|
|
})
|
|
}
|
|
|
|
func (s *Service) DeleteUser(ctx context.Context, id int64) error {
|
|
// Delete User
|
|
return s.userStore.DeleteUser(ctx, id)
|
|
}
|
|
|
|
func (s *Service) GetAllUsers(ctx context.Context, filter domain.UserFilter) ([]domain.User, int64, error) {
|
|
// Get all Users
|
|
return s.userStore.GetAllUsers(ctx, &filter.Role, &filter.OrganizationID.Value, &filter.Query.Value, &filter.CreatedBefore.Value, &filter.CreatedAfter.Value, int32(filter.PageSize.Value), int32(filter.Page.Value))
|
|
}
|
|
func (s *Service) GetUserById(ctx context.Context, id int64) (domain.User, error) {
|
|
|
|
return s.userStore.GetUserByID(ctx, id)
|
|
}
|