irc-radio-bot/libs/Db.js
2019-12-24 16:30:45 +01:00

35 lines
770 B
JavaScript

class Db {
constructor (models) {
this.models = models
}
/**
* Fonction sauvegardant en historique le morceau en cours de lecture
* @param {Object} value
*/
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