songs.js 467 B

12345678910111213141516171819202122232425
  1. 'use strict';
  2. const db = require('../db');
  3. module.exports = {
  4. index: (session, cb) => {
  5. db.models.song.find({}, (err, songs) => {
  6. if (err) throw err;
  7. cb(songs);
  8. });
  9. },
  10. update: (session, song, cb) => {
  11. db.models.song.findOneAndUpdate({ id: song.id }, song, { upsert: true }, (err, updatedSong) => {
  12. if (err) throw err;
  13. cb(updatedSong);
  14. });
  15. },
  16. remove: (session, song, cb) => {
  17. db.models.song.find({ id: song.id }).remove().exec();
  18. }
  19. };