stufflog graphql server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

46 lines
1.3 KiB

package resolvers
// This file will be automatically regenerated based on the schema, any resolver implementations
// will be copied through when generating and any unknown code will be moved to the end.
import (
"context"
"git.aiterp.net/stufflog/server/graph/loaders"
"git.aiterp.net/stufflog/server/graph/graphcore"
"git.aiterp.net/stufflog/server/models"
)
func (r *issueItemResolver) Issue(ctx context.Context, obj *models.IssueItem) (*models.Issue, error) {
return loaders.IssueLoaderFromContext(ctx).Load(obj.IssueID)
}
func (r *issueItemResolver) Item(ctx context.Context, obj *models.IssueItem) (*models.Item, error) {
return r.Database.Items().Find(ctx, obj.ItemID)
}
func (r *issueItemResolver) Remaining(ctx context.Context, obj *models.IssueItem) (int, error) {
if obj.Acquired {
return 0, nil
}
loader := loaders.LogsByIssueLoaderFromContext(ctx)
logs, err := loader.Load(obj.IssueID)
if err != nil {
return 0, err
}
remaining := obj.Quantity
for _, log := range logs {
if item := log.Item(obj.ID); item != nil {
remaining -= item.Amount
}
}
return remaining, nil
}
// IssueItem returns graphcore.IssueItemResolver implementation.
func (r *Resolver) IssueItem() graphcore.IssueItemResolver { return &issueItemResolver{r} }
type issueItemResolver struct{ *Resolver }