songs.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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, id, song, cb) => {
  11. //TODO Require admin/login
  12. db.models.song.findOneAndUpdate({ id }, song, { upsert: true }, (err, updatedSong) => {
  13. if (err) throw err;
  14. cb(updatedSong);
  15. });
  16. },
  17. remove: (session, _id, cb) => {
  18. //TODO Require admin/login
  19. db.models.song.find({ _id }).remove().exec();
  20. },
  21. add: (session, song, cb) => {
  22. //TODO Require admin/login
  23. console.log(session.logged_in);
  24. // if (!session.logged_in) return cb({ status: 'failure', message: 'You must be logged in to add a song' });
  25. const newSong = new db.models.song(song);
  26. newSong.save(err => {
  27. if (err) throw err;
  28. else cb({ status: 'success', message: 'Song has been moved from Queue' })
  29. });
  30. //TODO Check if video already in songs list
  31. //TODO Check if video is in queue
  32. //TODO Add the song to the appropriate stations
  33. }
  34. };