Added db library
This commit is contained in:
parent
b9469d89b5
commit
b3cc482d66
1 changed files with 31 additions and 0 deletions
31
libs/Db.js
Normal file
31
libs/Db.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
|
||||
class Db {
|
||||
constructor (models) {
|
||||
this.models = models
|
||||
}
|
||||
|
||||
saveSong (value) {
|
||||
// Find if previous song was the same (on bot reload)
|
||||
this.models.Histories
|
||||
.find({})
|
||||
.sort({
|
||||
createdAt: 'desc'
|
||||
})
|
||||
.limit(1)
|
||||
.exec(function (err, last) {
|
||||
if (err ||
|
||||
last.length === 0 ||
|
||||
(last[0] !== undefined &&
|
||||
last[0].artist !== value.artist &&
|
||||
last[0].song !== value.song
|
||||
)
|
||||
) {
|
||||
// Previous song was different => save song!
|
||||
const history = new this.models.Histories(value)
|
||||
history.save()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Db
|
Loading…
Reference in a new issue