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.
37 lines
811 B
37 lines
811 B
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"
|
|
)
|
|
|
|
// RemoveLogArgs is args for the removeLog mutation
|
|
type RemoveLogArgs struct {
|
|
ID string
|
|
}
|
|
|
|
// RemoveLog resolves the removeLog mutation
|
|
func (r *MutationResolver) RemoveLog(ctx context.Context, args *RemoveLogArgs) (*types.LogResolver, error) {
|
|
token := auth.TokenFromContext(ctx)
|
|
if !token.Permitted("log.remove") {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
|
|
log, err := log.FindID(args.ID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
err = log.Remove()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
go change.Submit("Log", "remove", token.UserID, log.ID, nil)
|
|
|
|
return &types.LogResolver{L: log}, nil
|
|
}
|