Преглед на файлове

Worked more on errors and limits. Queue validation still not completely fixed.

KrisVos130 преди 8 години
родител
ревизия
a85e008969
променени са 3 файла, в които са добавени 10 реда и са изтрити 6 реда
  1. 1 1
      backend/logic/db/index.js
  2. 8 4
      backend/logic/utils.js
  3. 1 1
      backend/package.json

+ 1 - 1
backend/logic/db/index.js

@@ -93,7 +93,7 @@ let lib = {
 				queue.forEach((song) => {
 					totalDuration += song.duration;
 				});
-				return callback(totalDuration <= 3600);
+				return callback(totalDuration <= 3600 * 3);
 			}, 'The max length of the queue is 3 hours.');
 
 			lib.schemas.station.path('queue').validate((queue, callback) => {

+ 8 - 4
backend/logic/utils.js

@@ -2,6 +2,7 @@
 
 const moment  = require('moment'),
 	  io      = require('./io'),
+	  db      = require('./db'),
 	  config  = require('config'),
 	  async	  = require('async'),
 	  request = require('request'),
@@ -422,26 +423,29 @@ module.exports = {
 	getError: (err) => {
 		let error = 'An error occurred.';
 		if (typeof err === "string") error = err;
-		else if (err.message) error = err.message;
+		else if (err.message) {
+			if (err.message !== 'Validation failed') error = err.message;
+			else error = err.errors[Object.keys(err.errors)].message;
+		}
 		return error;
 	},
 	canUserBeInStation: (station, userId, cb) => {
 		async.waterfall([
 			(next) => {
 				if (station.privacy !== 'private') return next(true);
-				if (!session.userId) return next(false);
+				if (!userId) return next(false);
 				next();
 			},
 
 			(next) => {
-				db.models.user.findOne({_id: session.userId}, next);
+				db.models.user.findOne({_id: userId}, next);
 			},
 
 			(user, next) => {
 				if (!user) return next(false);
 				if (user.role === 'admin') return next(true);
 				if (station.type === 'official') return next(false);
-				if (station.owner === session.userId) return next(true);
+				if (station.owner === userId) return next(true);
 				next(false);
 			}
 		], (err) => {

+ 1 - 1
backend/package.json

@@ -22,7 +22,7 @@
     "express-session": "^1.14.0",
     "mailgun-js": "^0.8.0",
     "moment": "^2.15.2",
-    "mongoose": "^4.6.0",
+    "mongoose": "^4.9.0",
     "oauth": "^0.9.14",
     "passport": "^0.3.2",
     "passport-discord": "^0.1.1",