Fetch properties
This commit is contained in:
@@ -1,7 +1,11 @@
|
|||||||
import properties from '@/properties.json';
|
|
||||||
import PropertyCard from '@/components/PropertyCard';
|
import PropertyCard from '@/components/PropertyCard';
|
||||||
|
import Property from '@/models/Property';
|
||||||
|
import connectDB from '@/config/database';
|
||||||
|
|
||||||
|
const PropertiesPage = async () => {
|
||||||
|
await connectDB();
|
||||||
|
const properties = await Property.find({});
|
||||||
|
|
||||||
const PropertiesPage = () => {
|
|
||||||
return (
|
return (
|
||||||
<section className='px-4 py-6'>
|
<section className='px-4 py-6'>
|
||||||
<div className='container-xl lg:container m-auto px-4 py-6'>
|
<div className='container-xl lg:container m-auto px-4 py-6'>
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
import properties from '@/properties.json';
|
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import PropertyCard from './PropertyCard';
|
import PropertyCard from './PropertyCard';
|
||||||
|
import connectDB from '@/config/database';
|
||||||
|
import Property from '@/models/Property';
|
||||||
|
|
||||||
const HomeProperties = () => {
|
const HomeProperties = async () => {
|
||||||
const recentProperties = properties
|
await connectDB();
|
||||||
.sort(() => Math.random() - Math.random())
|
|
||||||
.slice(0, 3);
|
// Get the 3 latest properties
|
||||||
|
const recentProperties = await Property.find({})
|
||||||
|
.sort({ createdAt: -1 })
|
||||||
|
.limit(3)
|
||||||
|
.lean();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -25,6 +30,7 @@ const HomeProperties = () => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section className='m-auto max-w-lg my-10 px-6'>
|
<section className='m-auto max-w-lg my-10 px-6'>
|
||||||
<Link
|
<Link
|
||||||
href='/properties'
|
href='/properties'
|
||||||
|
|||||||
Reference in New Issue
Block a user