Documentation
¶
Index ¶
- type UserService
- func (s *UserService) CreateActivity(userID string, activity *models.UserActivityModel) error
- func (s *UserService) FinishActivityByActivityID(userID string, activityID string, latitude *float64, longitude *float64, ...) (*models.UserActivityModel, error)
- func (s *UserService) FinishActivityByID(activityID string) error
- func (s *UserService) FinishActivityByUser(userID string, activityType models.UserActivityType, latitude *float64, ...) (*models.UserActivityModel, error)
- func (service *UserService) GetCompanyUsers(companyID string, request http.Request) (paginate.Page, error)
- func (s *UserService) GetFilesByID(ID string) ([]models.FileModel, error)
- func (s *UserService) GetLastClockinByUser(userID string, companyID string, thresholdDuration time.Duration) (*models.UserActivityModel, error)
- func (s *UserService) GetUserActivitiesByUserID(userID string, request http.Request) (paginate.Page, error)
- func (service *UserService) GetUserByCode(code string) (*models.UserModel, error)
- func (service *UserService) GetUserByID(userID string) (*models.UserModel, error)
- func (service *UserService) GetUserByPhone(phoneNumber string) (*models.UserModel, error)
- func (s *UserService) GetUsers(request http.Request, search string) (paginate.Page, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type UserService ¶
type UserService struct {
// contains filtered or unexported fields
}
func NewUserService ¶
func NewUserService(erpContext *context.ERPContext) *UserService
NewUserService creates a new instance of UserService.
It takes an ERPContext as an argument.
It returns a pointer to a UserService.
func (*UserService) CreateActivity ¶
func (s *UserService) CreateActivity(userID string, activity *models.UserActivityModel) error
CreateActivity creates a user activity.
It takes a user ID and an activity as input. The method uses GORM to create the user activity in the database.
The function returns an error if the operation fails.
func (*UserService) FinishActivityByActivityID ¶
func (s *UserService) FinishActivityByActivityID(userID string, activityID string, latitude *float64, longitude *float64, notes *string) (*models.UserActivityModel, error)
FinishActivityByActivityID finishes the user activity with the given activity ID.
It takes a user ID and an activity ID as input. The method uses GORM to query the database for the user activity with the given ID and user ID. It then sets the finished_at field of the activity to the current time and calculates the duration of the activity. Finally, it updates the activity in the database.
The function returns the updated activity and an error if the operation fails.
func (*UserService) FinishActivityByID ¶
func (s *UserService) FinishActivityByID(activityID string) error
FinishActivityByID finishes the user activity with the given ID.
It takes an activity ID as input. The method uses GORM to query the database for the user activity with the given ID. It then sets the finished_at field of the activity to the current time and calculates the duration of the activity. Finally, it updates the activity in the database.
The function returns an error if the operation fails.
func (*UserService) FinishActivityByUser ¶
func (s *UserService) FinishActivityByUser(userID string, activityType models.UserActivityType, latitude *float64, longitude *float64, notes *string) (*models.UserActivityModel, error)
FinishActivityByUser finishes the last user activity of the given user ID with the given type.
It takes a user ID and an activity type as input. The method uses GORM to query the database for the last user activity with the given type and user ID. It then sets the finished_at field of the activity to the current time and calculates the duration of the activity. Finally, it updates the activity in the database.
The function returns the updated activity and an error if the operation fails.
func (*UserService) GetCompanyUsers ¶
func (service *UserService) GetCompanyUsers(companyID string, request http.Request) (paginate.Page, error)
GetCompanyUsers retrieves a paginated list of users associated with a specific company.
It takes a company ID and an HTTP request as input. The method uses GORM to query the database for users linked to the specified company ID. It also applies any necessary request modifications using the utils.FixRequest utility.
The function returns a paginated page of UserModel and an error if the operation fails.
func (*UserService) GetFilesByID ¶
func (s *UserService) GetFilesByID(ID string) ([]models.FileModel, error)
GetFilesByID retrieves a list of files associated with a given ID and reference type.
It takes a reference ID and a reference type as input. The method uses GORM to query the database for files linked to the specified reference ID and reference type.
The function returns a list of FileModel and an error if the operation fails.
func (*UserService) GetLastClockinByUser ¶
func (s *UserService) GetLastClockinByUser(userID string, companyID string, thresholdDuration time.Duration) (*models.UserActivityModel, error)
GetLastClockinByUser retrieves the last user activity of type clockin associated with a user ID.
It takes a user ID, a company ID, and a threshold duration as input. The method uses GORM to query the database for the last user activity of type clockin linked to the specified user ID and company ID, with a started_at timestamp greater than or equal to the current time minus the threshold duration.
The function returns the UserActivityModel if found, otherwise an error.
func (*UserService) GetUserActivitiesByUserID ¶
func (s *UserService) GetUserActivitiesByUserID(userID string, request http.Request) (paginate.Page, error)
GetUserActivitiesByUserID retrieves a paginated list of user activities associated with a user ID.
It takes a user ID and an HTTP request as input. The method uses GORM to query the database for user activities linked to the specified user ID. If the request contains an activity type, the method also filters the result by the activity type. If the request contains a company ID header, the method also filters the result by the company ID. The function utilizes pagination to manage the result set and applies any necessary request modifications using the utils.FixRequest utility.
The function returns a paginated page of UserActivityModel and an error if the operation fails.
func (*UserService) GetUserByCode ¶
func (service *UserService) GetUserByCode(code string) (*models.UserModel, error)
GetUserByCode returns a user by their code
It takes the code as an argument.
It returns the UserModel if found, otherwise an error.
func (*UserService) GetUserByID ¶
func (service *UserService) GetUserByID(userID string) (*models.UserModel, error)
GetUserByID returns a user by their ID
It takes the user ID as an argument.
It returns the UserModel if found, otherwise an error.
func (*UserService) GetUserByPhone ¶
func (service *UserService) GetUserByPhone(phoneNumber string) (*models.UserModel, error)
GetUserByPhone returns a user by their phone number
It takes the phone number as an argument.
It returns the UserModel if found, otherwise an error.
func (*UserService) GetUsers ¶
GetUsers retrieves a paginated list of users from the database.
It takes an HTTP request and a search query string as input. The method uses GORM to query the database for users, applying the search query to the full name, email, and phone number fields. The function utilizes pagination to manage the result set and applies any necessary request modifications using the utils.FixRequest utility.
The function returns a paginated page of UserModel and an error if the operation fails.