Updated saveSong function
This commit is contained in:
parent
a5a5d82969
commit
92825ab201
3 changed files with 29 additions and 39 deletions
|
@ -5,6 +5,34 @@ class ArtistSong {
|
|||
this.models = models
|
||||
}
|
||||
|
||||
/**
|
||||
* Fonction sauvegardant en historique le morceau en cours de lecture
|
||||
* @param {Object} value
|
||||
*/
|
||||
saveCurrent (value) {
|
||||
// Find if previous song was the same (on bot reload)
|
||||
this.models.Histories
|
||||
.find({})
|
||||
.sort({
|
||||
createdAt: 'desc'
|
||||
})
|
||||
.limit(1)
|
||||
.exec((err, last) => {
|
||||
if (err ||
|
||||
last.length === 0 ||
|
||||
(last[0] !== undefined &&
|
||||
last[0].artist !== value.artist &&
|
||||
last[0].title !== value.title
|
||||
)
|
||||
) {
|
||||
console.log('Save song!', value)
|
||||
// Previous song was different => save song!
|
||||
const history = new this.models.Histories(value)
|
||||
history.save()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Point d'entrée pour l'ajout suppression de favoris
|
||||
* @param {String} type
|
||||
|
|
36
libs/Db.js
36
libs/Db.js
|
@ -1,36 +0,0 @@
|
|||
|
||||
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((err, last) => {
|
||||
if (err ||
|
||||
last.length === 0 ||
|
||||
(last[0] !== undefined &&
|
||||
last[0].artist !== value.artist &&
|
||||
last[0].title !== value.title
|
||||
)
|
||||
) {
|
||||
console.log('Save song!', value)
|
||||
// Previous song was different => save song!
|
||||
const history = new this.models.Histories(value)
|
||||
history.save()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Db
|
Loading…
Add table
Add a link
Reference in a new issue