-
Notifications
You must be signed in to change notification settings - Fork 133
/
database.js
85 lines (78 loc) · 2.13 KB
/
database.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const mongoose = require('mongoose');
const bcrypt = require('bcrypt');
// Connect to MongoDB
mongoose
.connect(process.env.DB_URL)
.then(() => console.log('Connected to MongoDB'))
.catch(error => console.error('Error connecting to MongoDB:', error));
// Define the User schema
const userSchema = new mongoose.Schema({
username: { type: String, required: true, unique: true },
email: { type: String, required: true, unique: true },
phone: { type: String, required: true, unique: true },
password: { type: String, required: true },
});
// Define the Food schema
const foodSchema = new mongoose.Schema({
title: String,
image: String,
location: String,
price: Number,
latitude: String,
longitude: String,
description: String,
username: { type: String, required: true },
email: { type: String, required: true },
phone: { type: String, required: true },
});
// Define the House schema
const houseSchema = new mongoose.Schema({
title: String,
image: String,
location: String,
rent: Number,
latitude: String,
longitude: String,
description: String,
username: { type: String, required: true },
email: { type: String, required: true },
phone: { type: String, required: true },
});
// Define the Market schema
const marketSchema = new mongoose.Schema({
title: String,
image: String,
location: String,
price: Number,
latitude: String,
longitude: String,
description: String,
username: { type: String, required: true },
email: { type: String, required: true },
phone: { type: String, required: true },
});
// Define the Feedback schema
const feedbackSchema = new mongoose.Schema({
feedbackText: {
type: String,
required: true,
trim: true,
},
email: {
type: String,
trim: true,
match: /.+\@.+\..+/,
},
createdAt: {
type: Date,
default: Date.now,
},
});
// Export the models
module.exports = {
User: mongoose.model('User', userSchema),
Food: mongoose.model('Food', foodSchema),
House: mongoose.model('House', houseSchema),
Market: mongoose.model('Market', marketSchema),
Feedback: mongoose.model('Feedback', feedbackSchema), // Add Feedback model here
};