Saved Searches
Saved Searches
Section titled “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.
Collections
Section titled “Collections”Both live under the “User Data” group in the admin dashboard.
Saved Searches (saved-searches)
Section titled “Saved Searches (saved-searches)”frontend/payload/src/collections/SavedSearches.ts
| Field | Type | Notes |
|---|---|---|
user | relationship to users | The user is the owner of the saved search, and their contact info can be pulled through the relation. |
mode | select seeking / providing | The user’s “mode” when searching (seeking vs providing) |
type | select house / room / bed | Only applies to seekers |
search | text | Raw query typed by the user, like in the search bar. |
min_price / max_price | number | Self explanatory. |
amenities | relationship to amenities hasMany | Self explanatory. |
Access: users can only read their own saved searches currently, anyone logged in can create and remove their own listings.
Notifications (notifications)
Section titled “Notifications (notifications)”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).
| Field | Type | Notes |
|---|---|---|
user | relationship to users | Recipient of notification. |
listing_id | text | ID of the triggering listing. |
listing_type | select house / room / bed | Self explanatory. |
title | text | Self explanatory. |
url | text | Link built from FRONTEND_URL and listing.slug. Links to the listing in question |
read | checkbox | Self explanatory. |
Matching & Alerts
Section titled “Matching & Alerts”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:
notificationsentry 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>.
Testing
Section titled “Testing”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.
# .env needs TARGET_API_URL, SEED_ADMIN_EMAIL, SEED_ADMIN_PASSWORDpnpm test:alert <user-email># or: [email protected] pnpm test:alert