function generateWorkUpload(listId) {
    return new Promise((resolve, reject) => {
      Promise.all([
        List.findOne({
          listId: listId
        }),
        ListUser.find({
          listId: listId
        })
      ]).then(([list, relations]) => {
        relations.forEach(function (relation, index) {
          if (relation.updated == null)
            var newSongs = list.songs;
          else
            var newSongs = list.songs.filter(song => song.added > relation.updated);

          logger.debug(relation.email + " - Songs for new work:");
          logger.debug(JSON.stringify(newSongs));

          var upWorks = newSongs.map(function (song) {
            return {
              songId: song.songId,
              listId: listId,
              listName: relation.name,
              imageId: relation.imageId, //TODO: Quitarlo de aquí y que el demonio lo busque a la hora de subir musica
              email: relation.email,
              state: "new",
              dateLastMovement: Date.now(),
            }
          });

          //Para meter un array tiene que ir sin "{}"
          WorkTodo.insertMany(upWorks, function (err) {
            if (err) return reject(err.stack);

            relation.updated = Date.now();
            relation.save(function (err) {
              if (err) return reject(err.stack);
            });
          });

          if (index == relations.length - 1)
            return resolve(null);
        });
      }).catch(err => {
        return reject(err.stack);
      });
    });
  }
//Carga en workTodo todo aquello que haya que subir a googleMusic
Carga en workTodo todo aquello que haya que subir a googleMusic
Carga en workTodo todo aquello que haya que subir a googleMusic
function generateWorkUpload(listId) {
    return new Promise((resolve, reject) => {
      Promise.all([
        List.findOne({
          listId: listId
        }),
        ListUser.find({
          listId: listId
        })
      ]).then(([list, relations]) => {
        relations.forEach(function (relation, index) {
          if (relation.updated == null)
            var newSongs = list.songs;
          else
            var newSongs = list.songs.filter(song => song.added > relation.updated);
          logger.debug(relation.email + " - Songs for new work:");
          logger.debug(JSON.stringify(newSongs));
          var upWorks = newSongs.map(function (song) {
            return {
              songId: song.songId,
              listId: listId,
              listName: relation.name,
              imageId: relation.imageId, 
              email: relation.email,
              state: "new",
              dateLastMovement: Date.now(),
            }
          });
          WorkTodo.insertMany(upWorks, function (err) {
            if (err) return reject(err.stack);
            relation.updated = Date.now();
            relation.save(function (err) {
              if (err) return reject(err.stack);
            });
          });
          if (index == relations.length - 1)
            return resolve(null);
        });
      }).catch(err => {
        return reject(err.stack);
      });
    });
  }
function generateWorkUpload ( listId ) { return new Promise ( ( resolve , reject ) => { Promise . all ( [ List . findOne ( { listId : listId } ) , ListUser . find ( { listId : listId } ) ] ) . then ( ( [ list , relations ] ) => { relations . forEach ( function ( relation , index ) { if ( relation . updated == null ) var newSongs = list . songs ; else var newSongs = list . songs . filter ( song => song . added > relation . updated ) ; logger . debug ( relation . email + " - Songs for new work:" ) ; logger . debug ( JSON . stringify ( newSongs ) ) ; var upWorks = newSongs . map ( function ( song ) { return { songId : song . songId , listId : listId , listName : relation . name , imageId : relation . imageId , email : relation . email , state : "new" , dateLastMovement : Date . now ( ) , } } ) ; WorkTodo . insertMany ( upWorks , function ( err ) { if ( err ) return reject ( err . stack ) ; relation . updated = Date . now ( ) ; relation . save ( function ( err ) { if ( err ) return reject ( err . stack ) ; } ) ; } ) ; if ( index == relations . length - 1 ) return resolve ( null ) ; } ) ; } ) . catch ( err => { return reject ( err . stack ) ; } ) ; } ) ; }
Carga en workTodo todo aquello que haya que subir a googleMusic
Carga en workTodo todo aquello que haya que subir a googleMusic
//TODO: Quitarlo de aquí y que el demonio lo busque a la hora de subir musica //Para meter un array tiene que ir sin "{}"