feat: add party-size queueing and call modes
This commit is contained in:
34
server/internal/httpapi/experienced_people.go
Normal file
34
server/internal/httpapi/experienced_people.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"calllinesystem/server/internal/domain"
|
||||
"calllinesystem/server/internal/model"
|
||||
)
|
||||
|
||||
// displayedExperiencedPeople returns the current project's public daily
|
||||
// metric. A queue session is created lazily on the first ticket, so a nil
|
||||
// session intentionally still returns the configured starting display value.
|
||||
func (s *Server) displayedExperiencedPeople(ctx context.Context, project model.Project, session *model.QueueSession) (int64, error) {
|
||||
var actual int64
|
||||
if session != nil {
|
||||
location, err := time.LoadLocation(project.Timezone)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("invalid project timezone: %w", err)
|
||||
}
|
||||
businessDate := s.now().In(location).Format("2006-01-02")
|
||||
if session.BusinessDate.Format("2006-01-02") != businessDate {
|
||||
return domain.DisplayExperiencedPeople(project.ExperiencedPeopleStart, 0), nil
|
||||
}
|
||||
if err := s.db.WithContext(ctx).Model(&model.QueueTicket{}).
|
||||
Select("COALESCE(sum(party_size), 0)").
|
||||
Where("project_id = ? AND queue_session_id = ?", project.ID, session.ID).
|
||||
Scan(&actual).Error; err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
return domain.DisplayExperiencedPeople(project.ExperiencedPeopleStart, actual), nil
|
||||
}
|
||||
Reference in New Issue
Block a user