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