Database connect and Mongoose models

This commit is contained in:
Brad Traversy
2024-07-09 11:51:16 -04:00
parent 26440f4118
commit abfd74dc44
5 changed files with 430 additions and 0 deletions
+91
View File
@@ -0,0 +1,91 @@
import { Schema, model, models } from 'mongoose';
const PropertySchema = new Schema(
{
owner: {
type: Schema.Types.ObjectId,
ref: 'User',
required: true,
},
name: {
type: String,
required: true,
},
type: {
type: String,
required: true,
},
description: {
type: String,
},
location: {
street: {
type: String,
},
city: {
type: String,
},
state: {
type: String,
},
zipcode: {
type: String,
},
},
beds: {
type: Number,
required: true,
},
baths: {
type: Number,
required: true,
},
square_feet: {
type: Number,
required: true,
},
amenities: [
{
type: String,
},
],
rates: {
nightly: {
type: Number,
},
weekly: {
type: Number,
},
monthly: {
type: Number,
},
},
seller_info: {
name: {
type: String,
},
email: {
type: String,
},
phone: {
type: String,
},
},
images: [
{
type: String,
},
],
is_featured: {
type: Boolean,
default: false,
},
},
{
timestamps: true,
}
);
const Property = models.Property || model('Property', PropertySchema);
export default Property;
+31
View File
@@ -0,0 +1,31 @@
import { Schema, model, models } from 'mongoose';
const UserSchema = new Schema(
{
email: {
type: String,
unique: [true, 'Email already exists'],
required: [true, 'Email is required'],
},
username: {
type: String,
required: [true, 'Username is required'],
},
image: {
type: String,
},
bookmarks: [
{
type: Schema.Types.ObjectId,
ref: 'Property',
},
],
},
{
timestamps: true,
}
);
const User = models.User || model('User', UserSchema);
export default User;