Skip to content

Saved Searches

Saved searches let a user save a search (search query, filters, etc.) and get notified when a new providing listing matches it. The check runs server-side and is triggered upon listing creation.

Both live under the “User Data” group in the admin dashboard.

frontend/payload/src/collections/SavedSearches.ts

FieldTypeNotes
userrelationship to usersThe user is the owner of the saved search, and their contact info can be pulled through the relation.
modeselect seeking / providingThe user’s “mode” when searching (seeking vs providing)
typeselect house / room / bedOnly applies to seekers
searchtextRaw query typed by the user, like in the search bar.
min_price / max_pricenumberSelf explanatory.
amenitiesrelationship to amenities hasManySelf explanatory.

Access: users can only read their own saved searches currently, anyone logged in can create and remove their own listings.

frontend/payload/src/collections/Notifications.ts

Created automatically when a match is found. Used as a log for administrators, and can serve as an alternative source of notifications (i.e. for display in the app or frontend).

FieldTypeNotes
userrelationship to usersRecipient of notification.
listing_idtextID of the triggering listing.
listing_typeselect house / room / bedSelf explanatory.
titletextSelf explanatory.
urltextLink built from FRONTEND_URL and listing.slug. Links to the listing in question
readcheckboxSelf explanatory.

The frontend/payload/src/hooks/notifySavedSearchMatches.ts script fires upon listing creation, and checks for saved searches that match the new listing. If a match is found, a notification is created and an email is sent to the saved search owner.

When matched:

  • notifications entry is created
  • Email is sent via the native SMTP configuration.

FRONTEND_URL from .env (fallback https://p27astro.benb.au) is used for the permalink: /en/listing/<slug>?type=<type>.

Script: frontend/payload/src/scripts/test-saved-search-alert.ts

Creates a saved search for a target user, then creates a matching listing. This should trigger the hook, send an email, and log it in the notifications collection.

Terminal window
# .env needs TARGET_API_URL, SEED_ADMIN_EMAIL, SEED_ADMIN_PASSWORD
pnpm test:alert <user-email>
# or: [email protected] pnpm test:alert

See the email page for more info.