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.
51 lines
1.1 KiB
51 lines
1.1 KiB
package mutations
|
|
|
|
import (
|
|
"context"
|
|
|
|
"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"
|
|
)
|
|
|
|
// LogEditArgs is args for the editLog mutation
|
|
type LogEditArgs struct {
|
|
Input *struct {
|
|
ID string
|
|
Title *string
|
|
Event *string
|
|
Description *string
|
|
Open *bool
|
|
}
|
|
}
|
|
|
|
// EditLog resolves the editLog mutation
|
|
func (r *MutationResolver) EditLog(ctx context.Context, args *LogEditArgs) (*types.LogResolver, error) {
|
|
input := args.Input
|
|
|
|
token := auth.TokenFromContext(ctx)
|
|
if !token.Permitted("log.edit") {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
|
|
log, err := log.FindID(input.ID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
err = log.Edit(input.Title, input.Event, input.Description, input.Open)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
go change.Submit("Log", "edit", token.UserID, log.ID, map[string]interface{}{
|
|
"channel": log.Channel,
|
|
"title": input.Title,
|
|
"event": input.Event,
|
|
"description": input.Description,
|
|
"open": input.Open,
|
|
})
|
|
|
|
return &types.LogResolver{L: log}, nil
|
|
}
|