-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathestablishmentsModel.js
91 lines (88 loc) · 2.06 KB
/
establishmentsModel.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
86
87
88
89
90
91
// chamar dependências
const mongoose = require('mongoose');
// criar o modelo de estabelecimento
var establishmentSchema = new mongoose.Schema({
// campos do estabelecimento
name: {
type: String,
required: true,
},
description: {
type: String,
required: true,
},
ownerId: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
},
address: {
cep: {
type: String,
required: true,
},
patio: {
type: String,
required: true,
},
complement: {
type: String,
required: false,
},
number: {
type: Number,
required: true,
},
neighborhood: {
type: String,
required: true,
},
city: {
type: String,
required: true,
},
state: {
type: String,
required: true,
},
},
employees: [{
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
}],
animals: [{
type: mongoose.Schema.Types.ObjectId,
ref: 'Animal',
}],
services: [{
name: {
type: String,
required: true,
},
description: {
type: String,
required: true,
},
isAvailable: {
type: Boolean,
required: true,
},
usersInterested: [{
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
}],
}],
});
// Criar um índice de texto que inclui os campos relevantes para facilitar a busca de algum conteúdo
establishmentSchema.index({
name: 'text',
description: 'text',
'address.cep': 'text',
'address.patio': 'text',
'address.neighborhood': 'text',
'address.city': 'text',
'address.state': 'text',
'services.name': 'text',
'services.description': 'text'
});
// exportar o modelo de estabelecimento
module.exports = mongoose.model('Establishment', establishmentSchema);