realtor-lp-backend/sql/property/fetch_with_realtor_id_paged...

37 lines
1.1 KiB
SQL

SELECT
p.id,
p.project_id,
p.realtor_id,
p.media as "media: _",
p.property_type as "property_type: _",
p.property_sale_type as "property_sale_type: _",
p.country,
p.city,
p.district,
p.order_index,
p.thumbnail_format as "thumbnail_format: _",
p.rooms,
p.bathrooms,
p.area,
p.parking_spots,
p.admin_tag,
p.time_created,
p.last_updated
FROM property p, property_arrangement pa
WHERE p.realtor_id = $1
AND pa.property_id = p.id
-- FILTERS
AND (pa.arrangement = $3 OR $3 IS null) -- Arrangement
AND (p.property_type = $4 OR $4 IS null) -- Property Type
AND (p.country = $5 OR $5 IS null) -- Country
AND (p.city = $6 OR $6 IS null) -- City
AND (p.district = $7 OR $7 IS null) -- District
AND (p.rooms = $8 OR $8 IS null) -- Room amount
AND (p.bathrooms = $9 OR $9 IS null) -- Bathroom amount
AND (p.area >= $10 OR $10 IS null) -- Area greater than
AND (p.parking_spots = $11 OR $11 IS null) -- Parking spots amount
AND (pa.price <= $12 OR $12 IS null) -- Price Less than
AND (pa.price >= $13 OR $13 IS null) -- Price Greater than
-- END OF FILTERS
ORDER BY p.time_created DESC
LIMIT 25 OFFSET $2;