function generateWorkDelete(listId, deleted) {
    return new Promise((resolve, reject) => {
      Promise.all([
        List.findOne({
          listId: listId
        }),
        ListUser.find({
          listId: listId
        })
      ]).then(([list, relations]) => {
        var deletedSongs = list.songs.filter(x => deleted.includes(x.songId));

        logger.debug("Songs for 'del' work:");
        logger.debug(JSON.stringify(deletedSongs));

        relations.forEach(function (relation, index) {

          var delWorks = deletedSongs.map(function (song) {
            return {
              songId: song.songId,
              gmusicId: song.gmusicId,
              listId: listId,
              listName: relation.name,
              email: relation.email,
              state: "del",
              dateLastMovement: Date.now(),
            }
          });

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

            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 eliminar de googleMusic
Carga en workTodo todo aquello que haya que eliminar de googleMusic
Carga en workTodo todo aquello que haya que eliminar de googleMusic
function generateWorkDelete(listId, deleted) {
    return new Promise((resolve, reject) => {
      Promise.all([
        List.findOne({
          listId: listId
        }),
        ListUser.find({
          listId: listId
        })
      ]).then(([list, relations]) => {
        var deletedSongs = list.songs.filter(x => deleted.includes(x.songId));
        logger.debug("Songs for 'del' work:");
        logger.debug(JSON.stringify(deletedSongs));
        relations.forEach(function (relation, index) {
          var delWorks = deletedSongs.map(function (song) {
            return {
              songId: song.songId,
              gmusicId: song.gmusicId,
              listId: listId,
              listName: relation.name,
              email: relation.email,
              state: "del",
              dateLastMovement: Date.now(),
            }
          });
          WorkTodo.insertMany(delWorks, function (err) {
            if (err) return reject(err.stack);
            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 generateWorkDelete ( listId , deleted ) { return new Promise ( ( resolve , reject ) => { Promise . all ( [ List . findOne ( { listId : listId } ) , ListUser . find ( { listId : listId } ) ] ) . then ( ( [ list , relations ] ) => { var deletedSongs = list . songs . filter ( x => deleted . includes ( x . songId ) ) ; logger . debug ( "Songs for 'del' work:" ) ; logger . debug ( JSON . stringify ( deletedSongs ) ) ; relations . forEach ( function ( relation , index ) { var delWorks = deletedSongs . map ( function ( song ) { return { songId : song . songId , gmusicId : song . gmusicId , listId : listId , listName : relation . name , email : relation . email , state : "del" , dateLastMovement : Date . now ( ) , } } ) ; WorkTodo . insertMany ( delWorks , function ( err ) { if ( err ) return reject ( err . stack ) ; 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 eliminar de googleMusic
Carga en workTodo todo aquello que haya que eliminar de googleMusic
//Para meter un array tiene que ir sin "{}"