-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.js
56 lines (44 loc) · 1.14 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
const mongoose = require('mongoose')
const Schema = mongoose.Schema
const peaksSchema = new Schema({
track: {
type: String,
required: true,
},
peaks: {
type: [Number],
required: true,
},
image: {
type: String,
required: true,
},
image_url: {
type: String,
required: false,
},
peaks_url: {
type: String,
required: false,
}
})
const Peaks = mongoose.model('PeaksModel', peaksSchema)
module.exports = Peaks
module.exports.getPeaks = function (limit, callback) {
Peaks.find({},{ image: 0, peaks: 0 }, callback, limit)
}
module.exports.getPeaksByUrl = function (track, callback) {
Peaks.findOne({ track }, { image: 0, peaks: 0 }, callback)
}
module.exports.addPeaks = function (peaks, callback) {
Peaks.create(peaks, callback)
}
module.exports.updatePeaks = function (track, peaks, callback) {
Peaks.findOneAndUpdate({ track }, peaks, { upsert: true, fields: { image: 0, peaks: 0 } }, callback)
}
module.exports.getPeaksWave = function(id, callback) {
Peaks.findById(id, 'image', callback)
}
module.exports.getPeaksList = function (id, callback) {
Peaks.findById(id, 'peaks', callback)
}