Use js hooks to prevent record being updated (0.23) #6101
Unanswered
andrewpmoore
asked this question in
Q&A
Replies: 1 comment 1 reply
-
|
How is this If you want to perform the check against the client submitted value then you can use the collection Update API rule for this with requirement like: If you want to do it with a hook, then you can attach either to the record model hooks or to the record request hooks (the latter gives you access to the request context, aka. the authenticated user, headers, etc.). For example: onRecordUpdateRequest((e) => {
if (e.hasSuperuserAuth()) {
return e.next() // ignore for superusers to allow setting any date
}
// see https://pocketbase.io/docs/js-records/#copies
let original = e.record.original();
if (original.getDateTime("updated_at").after(e.record.getDateTime("updated_at"))) {
throw new BadRequestError("updated_at must be after " + original.getDateTime("updated_at").string())
}
e.next()
}, "customer_store") |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a collection called
customer_store, it has a Date field calledupdated_at.I'm wanting that if the incoming update to that record has an
updated_attime before the record in the database that the record is rejected.I've got some other hooks working ok, but I feel like this should be simple, but I'm not sure how to do it.
Is there a way of getting the
newdata and thebeforedata to do a comparison and then reject based on that?Beta Was this translation helpful? Give feedback.
All reactions