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.
		
		
		
		
		
			
		
			
				
					
					
						
							70 lines
						
					
					
						
							1.4 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							70 lines
						
					
					
						
							1.4 KiB
						
					
					
				| package mutations | |
| 
 | |
| import ( | |
| 	"context" | |
| 	"time" | |
| 
 | |
| 	"git.aiterp.net/rpdata/api/graphql/resolver/types" | |
| 	"git.aiterp.net/rpdata/api/internal/auth" | |
| 	"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 | |
| 
 | |
| 	token := auth.TokenFromContext(ctx) | |
| 	if !token.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", token.UserID, 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 | |
| }
 |