Skip to content
This repository has been archived by the owner on Aug 28, 2021. It is now read-only.

Commit

Permalink
Make all sources compliant with ESLint
Browse files Browse the repository at this point in the history
  • Loading branch information
Logan Glasson committed Jul 20, 2018
1 parent 3569269 commit 88e9ce9
Show file tree
Hide file tree
Showing 19 changed files with 52 additions and 52 deletions.
2 changes: 1 addition & 1 deletion app/api/v1/accounts/UserCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = function( req, res ) {

User.findOne( { 'email': req.body.email } )
.then( user => {
if ( user ) throw new Error( 'Email taken. Please login. Thanks!')
if ( user ) throw new Error( 'Email taken. Please login. Thanks!' )
myUser.apitoken = 'JWT ' + jwt.sign( { _id: myUser._id }, sessionSecret, { expiresIn: '2y' } )
return myUser.save( )
} )
Expand Down
12 changes: 6 additions & 6 deletions app/api/v1/clients/ClientGet.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
const winston = require('winston')
const winston = require( 'winston' )

const Client = require( '../../../../models/UserAppClient')
const Client = require( '../../../../models/UserAppClient' )
const PermissionCheck = require( '../middleware/PermissionCheck' )

module.exports = ( req, res ) => {
if( !req.params.clientId ) {
if ( !req.params.clientId ) {
res.status( 400 )
return res.send( { success: false, message: 'Malformed request.'} )
}
Client.findOne( { _id: req.params.clientId } )
.then( result => PermissionCheck( req.user, 'read', result ) )
.then( result => {
if( !result ) throw new Error( 'No client found.' )
if ( !result ) throw new Error( 'No client found.' )
res.send( { success: true, message: 'Client found.', resource: result } )
})
} )
.catch( err => {
winston.error( err )
res.status( 400 )
res.send( { success: false, message: err.toString() } )
})
} )
}
2 changes: 1 addition & 1 deletion app/api/v1/clients/ClientPut.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Client = require( '../../../../models/UserAppClient' )
const PermissionCheck = require( '../middleware/PermissionCheck' )

module.exports = ( req, res ) => {
if ( !req.params.clientId || !req.body) {
if ( !req.params.clientId || !req.body ) {
res.status( 400 )
return res.send( { success: false, message: 'Malformed request.' } )
}
Expand Down
2 changes: 1 addition & 1 deletion app/api/v1/comments/CommentDelete.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = function( req, res ) {
.then( resource => resource.remove() )
.then( ( ) => {
res.send( { success: true, message: 'Comment deleted.' } )
})
} )
.catch( err => {
winston.error( err )
res.status( err.message.indexOf( 'authorised' ) >= 0 ? 401 : 404 )
Expand Down
2 changes: 1 addition & 1 deletion app/api/v1/middleware/BulkObjectSave.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = ( objects, user ) => {
return resolve( objects )

let notPlaceholders = objects.filter( obj => obj.type != 'Placeholder' )
if( notPlaceholders.length === 0 )
if ( notPlaceholders.length === 0 )
return resolve( objects )

SpeckleObject.find( { hash: { $in: objects.map( obj => obj.hash ) } }, '_id hash' )
Expand Down
2 changes: 1 addition & 1 deletion app/api/v1/middleware/GetResourceByType.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = ( type, id, populateFields ) => {
case 'objects':
return SpeckleObject.findOne( { _id: id } ).populate( populateFields )
case 'project':
case 'projects':
case 'projects':
return Project.findOne( { _id: id } ).populate( populateFields )
case 'comment':
case 'comments':
Expand Down
6 changes: 3 additions & 3 deletions app/api/v1/objects/ObjectDelete.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const SpeckleObject = require( '../../../../models/SpeckleObject' )
const PermissionCheck = require( '../middleware/PermissionCheck' )

module.exports = ( req, res ) => {
if( !req.params.objectId ) {
if ( !req.params.objectId ) {
res.status( 400 )
return res.send( { success: false, message: 'No objectId provided.' } )
}
Expand All @@ -15,10 +15,10 @@ module.exports = ( req, res ) => {
.then( obj => obj.remove() )
.then( ( ) => {
return res.send( { success: true, message: 'Object was deleted. Bye bye data.' } )
})
} )
.catch( err => {
winston.error( err )
res.status( err.message === 'Unauthorized. Please log in.' ? 401 : 404 )
res.send( { success: false, message: err.toString() } )
})
} )
}
2 changes: 1 addition & 1 deletion app/api/v1/objects/ObjectGet.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = ( req, res ) => {
res.status( 400 )
return res.send( { success: false, message: 'No object id provided.' } )
}

let query = PrepareQuery( req.query )

SpeckleObject.findOne( { _id: req.params.objectId }, query.options.fields )
Expand Down
2 changes: 1 addition & 1 deletion app/api/v1/streams/StreamDiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = ( req, res ) => {
let objects = { common: null, inA: null, inB: null }
first.objects = first.objects.map( o => o.toString( ) )
second.objects = second.objects.map( o => o.toString( ) )

objects.common = first.objects.filter( id => second.objects.includes( id ) )
objects.inA = first.objects.filter( id => !second.objects.includes( id ) )
objects.inB = second.objects.filter( id => !first.objects.includes( id ) )
Expand Down
2 changes: 1 addition & 1 deletion app/api/v1/streams/StreamObjectsGet.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = ( req, res ) => {
.then( objects => {
let list = streamObjects.reduce( ( arr, o ) => {
let match = objects.find( oo => oo._id == o )
if( match ) arr.push( match )
if ( match ) arr.push( match )
return arr
}, [ ] )
res.send( { success: true, resources: list, message: 'Object list returned. If querying, duplication of objects in list will not be respected.' } )
Expand Down
2 changes: 1 addition & 1 deletion app/ws/ClientStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = {

// push to my amazing datastore
this.clients.push( ws )
winston.debug( chalk.blue( `There are now ${this.clients.length} ws clients in ${process.pid}: ${this.clients.map( cl => cl.clientId)}` ) )
winston.debug( chalk.blue( `There are now ${this.clients.length} ws clients in ${process.pid}: ${this.clients.map( cl => cl.clientId )}` ) )
},

remove( ws ) {
Expand Down
24 changes: 12 additions & 12 deletions app/ws/middleware/VerifyClient.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
'use strict'
const winston = require('winston')
const chalk = require('chalk')
const url = require('url')
const User = require('../../../models/User')
const winston = require( 'winston' )
const chalk = require( 'chalk' )
const url = require( 'url' )
const User = require( '../../../models/User' )

module.exports = function( info, cb ) {
let location = url.parse(info.req.url, true);
let location = url.parse( info.req.url, true );
let token = location.query.access_token

winston.info( chalk.red.underline( 'WS: Access token: ' + token ) )
if( !token )
winston.info( chalk.red.underline( 'WS: Access token: ' + token ) )
if ( !token )
return cb( false, 401, 'Unauthorized' )

User.findOne( { apitoken: token } )
.then( user => {
if( !user ) throw new Error('WS Auth: User not found. ' + token)
return cb( true, 400, 'Authorized')
})
if ( !user ) throw new Error( 'WS Auth: User not found. ' + token )
return cb( true, 400, 'Authorized' )
} )
.catch( err => {
winston.error( err )
return cb( false, 401, 'Unauthorized' )
})
} )
}
4 changes: 2 additions & 2 deletions config/passport.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ module.exports = function( passport ) {
}

// returns 401 Unautorized, protects sensitive routes
passport.use( 'jwt-strict', new JwtStrategy( strictOptions, ( jwt_payload, done ) => {
User.findOne( { _id: jwt_payload._id } )
passport.use( 'jwt-strict', new JwtStrategy( strictOptions, ( jwtPayload, done ) => {
User.findOne( { _id: jwtPayload._id } )
.then( user => {
if ( !user ) throw new Error( 'No user found' )
winston.debug( chalk.bgBlue( 'Strict authentication' ), chalk.bgGreen( 'OK' ) )
Expand Down
2 changes: 1 addition & 1 deletion models/Comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var commentSchema = mongoose.Schema( {
text: { type: String, required: true },

// parent resource
resource: {
resource: {
resourceType: { type: String, required: true },
resourceId: { type: String, required: true }
},
Expand Down
4 changes: 2 additions & 2 deletions models/DataStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ var dataStreamSchema = mongoose.Schema( {

globalMeasures: { type: Object, default: {} },

isComputedResult: { type: Boolean, default: false },
isComputedResult: { type: Boolean, default: false },

objects: [ { type: mongoose.Schema.Types.ObjectId, ref: 'SpeckleObject' } ],

layers: { type: Array, default: [ ] },

viewerLayers: { type: Array, default: [ ] },

// versioning
Expand Down
4 changes: 2 additions & 2 deletions models/SpeckleDataTypesEnum.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = [
module.exports = [
'Null',
'Boolean',
'Number',
Expand All @@ -21,5 +21,5 @@ module.exports = [
'Brep',
'Annotation',
'Extrusion',
'Block',
'Block',
'Abstract' ]
24 changes: 12 additions & 12 deletions models/User.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var mongoose = require('mongoose')
var bcrypt = require('bcrypt-nodejs')
var mongoose = require( 'mongoose' )
var bcrypt = require( 'bcrypt-nodejs' )

var userSchema = mongoose.Schema({
var userSchema = mongoose.Schema( {
name: { type: String, default: 'John' },
surname: { type: String, default: 'Doe' },
email: { type: String, lowercase: true, unique: true, required: true, index: true },
Expand All @@ -16,25 +16,25 @@ var userSchema = mongoose.Schema({

userSchema.pre( 'save', function( next ) {
var user = this
if( this.isModified( 'password' ) || this.isNew ) {
if( user.password.length < 8 )
if ( this.isModified( 'password' ) || this.isNew ) {
if ( user.password.length < 8 )
return next( new Error( 'Password too short.' ) )
bcrypt.genSalt( 10, function ( err, salt ) {
if( err ) return next( err )
if ( err ) return next( err )
bcrypt.hash( user.password, salt, null, function ( err, hash ) {
if( err ) return next( err )
if ( err ) return next( err )
user.password = hash
next()
})
})
} )
} )
} else next() // means pass is not modified, so all is well
})
} )

userSchema.methods.validatePassword = ( pw, upw, cb ) => {
bcrypt.compare( pw, upw, ( err, res ) => {
if( res === true ) return cb( true )
if ( res === true ) return cb( true )
else return cb( false )
} )
}

module.exports = mongoose.model('User', userSchema)
module.exports = mongoose.model( 'User', userSchema )
4 changes: 2 additions & 2 deletions models/UserAppClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ var clientSchema = mongoose.Schema( {

documentName: { type: String },

documentGuid: { type: String }, // document unique id.
documentGuid: { type: String }, // document unique id.

documentType: { type: String }, // Rhino, Grasshopper, Node, Browser, etc.

documentLocation: { type: String }, // Location

streamId: { type: String }, // stream that we're connected to

online: { type: Boolean, default: true, strict: false }
online: { type: Boolean, default: true, strict: false }

}, { timestamps: true } )

Expand Down
2 changes: 1 addition & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ if ( cluster.isMaster ) {
////////////////////////////////////////////////////////////////////////
mongoose.Promise = global.Promise

mongoose.connect( process.env.MONGODB_URI, { auto_reconnect: true, reconnectTries: 5, keepAlive: 10 }, ( err ) => {
mongoose.connect( process.env.MONGODB_URI, { autoReconnect: true, reconnectTries: 5, keepAlive: 10 }, ( err ) => {
if ( err ) throw err
else winston.debug( 'connected to mongoose at ' + process.env.MONGODB_URI )
} )
Expand Down

0 comments on commit 88e9ce9

Please sign in to comment.