MCPcopy
hub / github.com/pocketbase/pocketbase / collectionUpdate

Function collectionUpdate

apis/collection.go:118–148  ·  view source on GitHub ↗
(e *core.RequestEvent)

Source from the content-addressed store, hash-verified

116}
117
118func collectionUpdate(e *core.RequestEvent) error {
119 collection, err := e.App.FindCollectionByNameOrId(e.Request.PathValue("collection"))
120 if err != nil || collection == nil {
121 return e.NotFoundError("", err)
122 }
123
124 if err := e.BindBody(collection); err != nil {
125 return e.BadRequestError("Failed to load the submitted data due to invalid formatting.", err)
126 }
127
128 event := new(core.CollectionRequestEvent)
129 event.RequestEvent = e
130 event.Collection = collection
131
132 return event.App.OnCollectionUpdateRequest().Trigger(event, func(e *core.CollectionRequestEvent) error {
133 if err := e.App.Save(e.Collection); err != nil {
134 // validation failure
135 var validationErrors validation.Errors
136 if errors.As(err, &validationErrors) {
137 return e.BadRequestError("Failed to update collection.", validationErrors)
138 }
139
140 // other generic db error
141 return e.BadRequestError("Failed to update collection. Raw error: \n"+err.Error(), nil)
142 }
143
144 return execAfterSuccessTx(true, e.App, func() error {
145 return e.JSON(http.StatusOK, e.Collection)
146 })
147 })
148}
149
150func collectionDelete(e *core.RequestEvent) error {
151 collection, err := e.App.FindCachedCollectionByNameOrId(e.Request.PathValue("collection"))

Callers

nothing calls this directly

Calls 10

execAfterSuccessTxFunction · 0.85
NotFoundErrorMethod · 0.80
BindBodyMethod · 0.80
BadRequestErrorMethod · 0.80
TriggerMethod · 0.80
JSONMethod · 0.80
SaveMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…