浏览代码

Fixed more issues that were discovered after we switched to mongoose.

KrisVos130 9 年之前
父节点
当前提交
010ec57ef0
共有 2 个文件被更改,包括 24 次插入21 次删除
  1. 15 6
      app/database/schemas.js
  2. 9 15
      app/server/server.js

+ 15 - 6
app/database/schemas.js

@@ -47,6 +47,14 @@ Schemas.FullSong = new SimpleSchema({
         label: "Song skipDuration",
         min: 0,
         decimal: true
+    },
+    "requestedBy": {
+        type: String,
+        label: "User ID of the person who requested the song"
+    },
+    "approvedBy": {
+        type: String,
+        label: "User ID of the person who approved the song"
     }
 });
 
@@ -98,7 +106,7 @@ Schemas.QueueSong = new SimpleSchema({
         min: 0,
         decimal: true
     },
-    "songs.$.requestedBy": {
+    "requestedBy": {
         type: String,
         label: "User ID of the person who requested the song"
     }
@@ -248,24 +256,25 @@ Schemas.Queue = new SimpleSchema({
 Schemas.UserProfile = new SimpleSchema({
     username: {
         type: String,
-        label: "User's Username",
+        label: "Username",
         regEx: /^[a-zA-Z0-9_]+$/,
         min: 6,
         max: 26
     },
     usernameL: {
         type: String,
-        label: "User's Username in lowercase",
+        label: "Username in lowercase",
         regEx: /^[a-z0-9_]+$/
     },
     realname: {
         type: String,
-        label: "User's Real Name",
-        regEx: /^[A-Za-z0-9 .'-]+$/
+        label: "Real Name",
+        regEx: /^[A-Za-z0-9 .'-]+$/,
+        optional: true
     },
     rank: {
         type: String,
-        label: "User's Rank",
+        label: "Rank",
         allowedValues: ["default", "moderator", "admin"]
     },
     liked: {

+ 9 - 15
app/server/server.js

@@ -19,6 +19,8 @@ Meteor.startup(function() {
     emojione.ascii = true;
 });
 
+var default_song = {id: "xKVcVSYmesU", mid: "ABCDEF", likes: 0, dislikes: 0, title: "Immortals", artist: "Fall Out Boy", img: "http://c.directlyrics.com/img/upload/fall-out-boy-sixth-album-cover.jpg", type: "YouTube", duration: 181, skipDuration: 0, requestedBy: "NONE", approvedBy: "NONE"};
+
 Alerts.update({active: true}, {$set: {active: false}}, { multi: true });
 
 var stations = [];
@@ -96,16 +98,8 @@ function getStation(type, cb) {
 
 function createRoom(display, tag, private) {
     var type = tag;
-    if (Rooms.find({type: type}).count() === 0 && private === false) {
-        Rooms.insert({display: display, type: type, users: 0}, function(err) {
-            if (err) {
-                throw err;
-            } else {
-                stations.push(new Station(type));
-            }
-        });
-    } else if (Rooms.find({type: type}).count() === 0 && private === true) {
-        Rooms.insert({display: display, type: type, users: 0, private: true}, function(err) {
+    if (Rooms.find({type: type}).count() === 0) {
+        Rooms.insert({display: display, type: type, users: 0, private: private, currentSong: {song: default_song, started: 0}}, function(err) {
             if (err) {
                 throw err;
             } else {
@@ -118,6 +112,11 @@ function createRoom(display, tag, private) {
 }
 
 function Station(type) {
+    if (Playlists.find({type: type}).count() === 0) {
+        Playlists.insert({type: type, songs: [default_song], lastSong: 0});
+    } else if (Playlists.findOne({type: type}).songs.length === 0) {
+        Playlists.update({type: type}, {$push: {songs: default_song}});
+    }
     Meteor.publish(type, function() {
         return undefined;
     });
@@ -126,11 +125,6 @@ function Station(type) {
     var playlist = Playlists.findOne({type: type});
     var songs = playlist.songs;
 
-    if (playlist.lastSong === undefined) {
-        Playlists.update({type: type}, {$set: {lastSong: 0}});
-        playlist = Playlists.findOne({type: type});
-        songs = playlist.songs;
-    }
     var currentSong = playlist.lastSong;
     if (currentSong < (songs.length - 1)) {
         currentSong++;