package mutations import ( "context" "time" "git.aiterp.net/rpdata/api/graphql/resolver/types" "git.aiterp.net/rpdata/api/internal/session" "git.aiterp.net/rpdata/api/model/change" "git.aiterp.net/rpdata/api/model/log" ) // LogAddArgs is args for the addLog mutation type LogAddArgs struct { Input *struct { Date string Channel string Title *string Open *bool Event *string Description *string } } // AddLog resolves the addLog mutation func (r *MutationResolver) AddLog(ctx context.Context, args *LogAddArgs) (*types.LogResolver, error) { input := args.Input user := session.FromContext(ctx).User() if user == nil || !user.Permitted("log.add") { return nil, ErrUnauthorized } date, err := time.Parse(time.RFC3339Nano, args.Input.Date) if err != nil { return nil, err } title := "" if input.Title != nil { title = *input.Title } event := "" if input.Event != nil { event = *input.Event } description := "" if input.Description != nil { description = *input.Description } open := input.Open != nil && *input.Open == true log, err := log.New(date, input.Channel, title, event, description, open) if err != nil { return nil, err } go change.Submit("Log", "add", user.ID, log.ID, map[string]interface{}{ "channel": log.Channel, "title": log.Title, "event": log.Event, "description": log.Description, "open": log.Open, }) return &types.LogResolver{L: log}, nil }