Files
wotra/internal/syncapi/hooks.go
T
aksdb f63fe1b549 ✨ Add batch push endpoint for synced collections
POST /api/sync/push applies up to 500 client changes of a signed-in
user in one transaction. Every change is answered with ok, stale,
forbidden or readonly, so the client can reconcile its local state
with the server state.

closed_days and closed_weeks are answered as readonly because only
the server computes them. The last remaining settings row of a user
cannot be deleted either; such a change is answered as stale, which
clients already treat as "server wins".
2026-11-29 17:03:42 +00:00

23 lines
632 B
Go

package syncapi
import (
"github.com/pocketbase/pocketbase/core"
"github.com/wotra/wotra/internal/collections"
)
func RegisterHooks(app core.App) {
app.OnRecordCreateRequest(collections.Synced...).BindFunc(func(e *core.RecordRequestEvent) error {
if e.Auth != nil && !e.HasSuperuserAuth() {
e.Record.Set("owner", e.Auth.Id)
}
e.Record.Set("rev", 1)
return e.Next()
})
app.OnRecordUpdateRequest(collections.Synced...).BindFunc(func(e *core.RecordRequestEvent) error {
orig := e.Record.Original()
e.Record.Set("owner", orig.GetString("owner"))
e.Record.Set("rev", orig.GetInt("rev")+1)
return e.Next()
})
}