-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.js
57 lines (50 loc) · 1.72 KB
/
model.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
const { Schema } = require("mongoose");
const fp = require("fastify-plugin");
module.exports = fp((fastify, opts, next) => {
let Mongoose = fastify.Mongoose;
let AuthedTeam = Mongoose.model(
"authed_team",
new Schema({
_id: { type: String, trim: true, required: true },
teamId: { type: String, trim: true, required: true },
name: { type: String, trim: true, required: true },
userId: { type: String, trim: true, required: true },
token: { type: String, required: true },
})
);
let RequesterSchema = new Schema({
_id: { type: String, required: true },
name: { type: String, trim: true, required: true },
userId: { type: String, required: true },
});
let SnackSchema = new Schema({
name: { type: String, required: true },
brand: { type: String },
description: { type: String },
imageUrl: { type: String },
upc: { type: String },
boxedId: { type: String },
});
let SnackRequest = Mongoose.model(
"snack_request",
new Schema({
originalRequestString: { type: String, trim: true, lowercase: true },
initialRequester: { type: RequesterSchema, required: true },
additionalRequesters: [RequesterSchema],
snack: { type: SnackSchema, required: true },
}).index(
{ originalRequestString: "text", "snack.name": "text" },
{
weights: {
originalRequestString: 5,
"snack.name": 10,
},
}
)
);
fastify.decorate("models", {
AuthedTeam,
SnackRequest,
});
next();
});