2022-11-17 14:17:10 +02:00
|
|
|
package models
|
|
|
|
|
2023-01-07 22:25:56 +02:00
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/pocketbase/pocketbase/models/schema"
|
|
|
|
)
|
|
|
|
|
2022-11-18 13:32:32 +02:00
|
|
|
// RequestData defines a HTTP request data struct, usually used
|
2022-11-17 14:17:10 +02:00
|
|
|
// as part of the `@request.*` filter resolver.
|
2022-11-18 13:32:32 +02:00
|
|
|
type RequestData struct {
|
2023-06-23 13:38:13 +03:00
|
|
|
Method string `json:"method"`
|
|
|
|
Query map[string]any `json:"query"`
|
|
|
|
// @todo consider changing to Body?
|
2023-03-23 19:30:35 +02:00
|
|
|
Data map[string]any `json:"data"`
|
|
|
|
Headers map[string]any `json:"headers"`
|
|
|
|
AuthRecord *Record `json:"authRecord"`
|
|
|
|
Admin *Admin `json:"admin"`
|
2022-11-17 14:17:10 +02:00
|
|
|
}
|
2023-01-07 22:25:56 +02:00
|
|
|
|
|
|
|
// HasModifierDataKeys loosely checks if the current struct has any modifier Data keys.
|
|
|
|
func (r *RequestData) HasModifierDataKeys() bool {
|
|
|
|
allModifiers := schema.FieldValueModifiers()
|
|
|
|
|
|
|
|
for key := range r.Data {
|
|
|
|
for _, m := range allModifiers {
|
|
|
|
if strings.HasSuffix(key, m) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|