From c053dc0b37b2c16134381b22b24ed1162c515673 Mon Sep 17 00:00:00 2001 From: Mathieu Hermann Date: Sun, 15 Dec 2024 14:14:16 +0100 Subject: [PATCH] chore(app): update gitignore and add pb_hooks --- .gitignore | 3 ++- backend/pb_hooks/tracks.pb.js | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 backend/pb_hooks/tracks.pb.js diff --git a/.gitignore b/.gitignore index ffe11f5..7eacb61 100644 --- a/.gitignore +++ b/.gitignore @@ -44,4 +44,5 @@ Thumbs.db # Pocketbase backend/* -!backend/pb_migrations \ No newline at end of file +!backend/pb_migrations +!backend/pb_hooks \ No newline at end of file diff --git a/backend/pb_hooks/tracks.pb.js b/backend/pb_hooks/tracks.pb.js new file mode 100644 index 0000000..319d006 --- /dev/null +++ b/backend/pb_hooks/tracks.pb.js @@ -0,0 +1,12 @@ +/// + +// Track creation +onRecordCreateRequest((e) => { + if(e.requestInfo().auth) { + // Set owner to the user who created the track + e.record.set("owner", e.requestInfo().auth.get("id").toString()); + // Activating the track + e.record.set("active", true); + } + e.next() +}, 'tracks'); \ No newline at end of file