Skip to content

Commit

Permalink
gql: add field "assignedSchedules" to type "User" (#3231)
Browse files Browse the repository at this point in the history
* add target to OnCallShift in schema

* inline call

* update schema - todo: gql hanging on query

* remove temp sched broken ref

* limit HistoryBySchedule to 3 concurrent calls

* fix tests

* revert

* use sqlc

* fix

* move

* lint

* use validate many

* remove unused used userIDs arg

* simplify query calls

* use passed db for transaction

* fix func call

* convert to NullUUID within gql layer

* remove unused query reference

* fix query reference

---------

Co-authored-by: Nathaniel Caza <[email protected]>
  • Loading branch information
Forfold and mastercactapus authored Oct 27, 2023
1 parent b065948 commit 8480382
Show file tree
Hide file tree
Showing 12 changed files with 327 additions and 18 deletions.
51 changes: 51 additions & 0 deletions gadb/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

148 changes: 144 additions & 4 deletions graphql2/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 26 additions & 2 deletions graphql2/graphqlapp/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"database/sql"
"errors"
"fmt"
"slices"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -81,14 +82,37 @@ func (q *Query) Schedule(ctx context.Context, id string) (*schedule.Schedule, er
return (*App)(q).FindOneSchedule(ctx, id)
}

func (s *Schedule) Shifts(ctx context.Context, raw *schedule.Schedule, start, end time.Time) ([]oncall.Shift, error) {
func (s *Schedule) Shifts(ctx context.Context, raw *schedule.Schedule, start, end time.Time, userIDs []string) ([]oncall.Shift, error) {
if end.Before(start) {
return nil, validation.NewFieldError("EndTime", "must be after StartTime")
}
if end.After(start.AddDate(0, 0, 50)) {
return nil, validation.NewFieldError("EndTime", "cannot be more than 50 days past StartTime")
}
return s.OnCallStore.HistoryBySchedule(ctx, raw.ID, start, end)

err := validate.ManyUUID("userID", userIDs, 50)
if err != nil {
return nil, err
}

shifts, err := s.OnCallStore.HistoryBySchedule(ctx, raw.ID, start, end)
if err != nil {
return nil, err
}

// filter by slice of userIDs if given
if userIDs != nil {
var filteredShifts []oncall.Shift
for _, shift := range shifts {
if slices.Contains(userIDs, shift.UserID) {
filteredShifts = append(filteredShifts, shift)
}
}

return filteredShifts, nil
}

return shifts, nil
}

func (s *Schedule) TemporarySchedules(ctx context.Context, raw *schedule.Schedule) ([]schedule.TemporarySchedule, error) {
Expand Down
Loading

0 comments on commit 8480382

Please sign in to comment.