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

Commit

Permalink
Enable ESLint rule no-unused-vars and make all sources compliant
Browse files Browse the repository at this point in the history
  • Loading branch information
Logan Glasson committed Jul 20, 2018
1 parent 9ffa0b7 commit c43e678
Show file tree
Hide file tree
Showing 41 changed files with 41 additions and 107 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ module.exports = {
"sourceType": "module"
},
"rules": {
"no-unused-vars": "off",
"no-console": "off",
"no-dupe-keys": "off"
}
Expand Down
3 changes: 1 addition & 2 deletions app/api/v1/accounts/UserCreate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const winston = require( 'winston' )
const chalk = require( 'chalk' )
const jwt = require( 'jsonwebtoken' )

const User = require( '../../../../models/User' )
Expand All @@ -17,7 +16,7 @@ module.exports = function( req, res ) {
surname: req.body.surname ? req.body.surname : '',
apitoken: null
} )

let sessionSecret = process.env.SESSION_SECRET

User.findOne( { 'email': req.body.email } )
Expand Down
1 change: 0 additions & 1 deletion app/api/v1/accounts/UserGet.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const winston = require( 'winston' )
const chalk = require( 'chalk' )

const User = require( '../../../../models/User' )

Expand Down
1 change: 0 additions & 1 deletion app/api/v1/accounts/UserLogin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const winston = require( 'winston' )
const chalk = require( 'chalk' )
const jwt = require( 'jsonwebtoken' )

const User = require( '../../../../models/User' )
Expand Down
1 change: 0 additions & 1 deletion app/api/v1/accounts/UserProfile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict'
const winston = require( 'winston' )
const chalk = require( 'chalk' )

const User = require( '../../../../models/User' )

Expand Down
3 changes: 1 addition & 2 deletions app/api/v1/accounts/UserPut.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict'
const winston = require( 'winston' )
const chalk = require( 'chalk' )

const User = require( '../../../../models/User' )

Expand All @@ -19,7 +18,7 @@ module.exports = function( req, res ) {
user.markModified( 'email' )
return user.save( )
} )
.then( result => {
.then( ( ) => {
res.send( { success: true, message: 'User profile updated.' } )
} )
.catch( err => {
Expand Down
1 change: 0 additions & 1 deletion app/api/v1/accounts/UserSearch.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict'
const winston = require( 'winston' )
const chalk = require( 'chalk' )

const User = require( '../../../../models/User' )

Expand Down
3 changes: 1 addition & 2 deletions app/api/v1/clients/ClientDelete.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict'
const winston = require( 'winston' )
const chalk = require( 'chalk' )

const Client = require( '../../../../models/UserAppClient' )
const PermissionCheck = require( '../middleware/PermissionCheck' )
Expand All @@ -16,7 +15,7 @@ module.exports = ( req, res ) => {
.then( client => {
return client.remove( )
} )
.then( result => {
.then( ( ) => {
return res.send( { success: true, message: 'Client was deleted! Bye bye data.' } )
} )
.catch( err => {
Expand Down
3 changes: 1 addition & 2 deletions app/api/v1/clients/ClientGet.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const winston = require('winston')
const chalk = require('chalk')

const Client = require( '../../../../models/UserAppClient')
const PermissionCheck = require( '../middleware/PermissionCheck' )
Expand All @@ -9,7 +8,7 @@ module.exports = ( req, res ) => {
res.status( 400 )
return res.send( { success: false, message: 'Malformed request.'} )
}
Client.findOne( { _id: req.params.clientId } )
Client.findOne( { _id: req.params.clientId } )
.then( result => PermissionCheck( req.user, 'read', result ) )
.then( result => {
if( !result ) throw new Error( 'No client found.' )
Expand Down
1 change: 0 additions & 1 deletion app/api/v1/clients/ClientGetAll.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict'
const winston = require( 'winston' )
const chalk = require( 'chalk' )

const UserAppClient = require( '../../../../models/UserAppClient' )

Expand Down
5 changes: 2 additions & 3 deletions app/api/v1/clients/ClientPost.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const winston = require( 'winston' )
const chalk = require( 'chalk' )
const Client = require( '../../../../models/UserAppClient' )

module.exports = ( req, res ) => {
Expand All @@ -9,10 +8,10 @@ module.exports = ( req, res ) => {
}

let myClient = new Client( req.body )

if ( !req.user )
return res.send( { success: true, message: 'Anonymous client created.', resource: { _id: 'temp-' + myClient._id } } )
else
else
myClient.owner = req.user._id

myClient.save( )
Expand Down
3 changes: 1 addition & 2 deletions app/api/v1/clients/ClientPut.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const winston = require( 'winston' )
const chalk = require( 'chalk' )

const Client = require( '../../../../models/UserAppClient' )
const PermissionCheck = require( '../middleware/PermissionCheck' )
Expand All @@ -12,7 +11,7 @@ module.exports = ( req, res ) => {
Client.findOne( { _id: req.params.clientId } )
.then( resource => PermissionCheck( req.user, 'write', resource, Object.keys( req.body ) ) )
.then( resource => resource.set( req.body ).save( ) )
.then( resource => {
.then( ( ) => {
res.send( { success: true, message: 'Client updated following fields: ' + Object.keys( req.body ) } )
} )
.catch( err => {
Expand Down
4 changes: 1 addition & 3 deletions app/api/v1/comments/CommentDelete.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
const winston = require( 'winston' )
const chalk = require( 'chalk' )

const Comment = require( '../../../../models/Comment' )
const PermissionCheck = require( '../middleware/PermissionCheck' )
const GetResource = require( '../middleware/GetResourceByType' )

module.exports = function( req, res ) {
if ( !req.params.commentId ) {
Expand All @@ -14,7 +12,7 @@ module.exports = function( req, res ) {
Comment.findOne( { _id: req.params.commentId } )
.then( resource => PermissionCheck( req.user, 'delete', resource ) )
.then( resource => resource.remove() )
.then( result => {
.then( ( ) => {
res.send( { success: true, message: 'Comment deleted.' } )
})
.catch( err => {
Expand Down
1 change: 0 additions & 1 deletion app/api/v1/comments/CommentGet.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const winston = require( 'winston' )
const chalk = require( 'chalk' )

const Comment = require( '../../../../models/Comment' )

Expand Down
2 changes: 0 additions & 2 deletions app/api/v1/comments/CommentGetAll.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const winston = require( 'winston' )
const chalk = require( 'chalk' )

const Comment = require( '../../../../models/Comment' )
const PermissionCheck = require( '../middleware/PermissionCheck' )

module.exports = ( req, res ) => {

Expand Down
2 changes: 0 additions & 2 deletions app/api/v1/comments/CommentGetAssigned.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const winston = require( 'winston' )
const chalk = require( 'chalk' )

const Comment = require( '../../../../models/Comment' )
const PermissionCheck = require( '../middleware/PermissionCheck' )

module.exports = ( req, res ) => {

Expand Down
6 changes: 0 additions & 6 deletions app/api/v1/comments/CommentGetFromResource.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
const winston = require( 'winston' )
const chalk = require( 'chalk' )

const Comment = require( '../../../../models/Comment' )
const DataStream = require( '../../../../models/DataStream' )
const SpeckleObject = require( '../../../../models/SpeckleObject' )
const Project = require( '../../../../models/Project' )

const PermissionCheck = require( '../middleware/PermissionCheck' )
const GetResource = require( '../middleware/GetResourceByType' )
Expand Down
4 changes: 0 additions & 4 deletions app/api/v1/comments/CommentPost.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
const winston = require( 'winston' )
const chalk = require( 'chalk' )

const Comment = require( '../../../../models/Comment' )
const DataStream = require( '../../../../models/DataStream' )
const SpeckleObject = require( '../../../../models/SpeckleObject' )
const Project = require( '../../../../models/Project' )

const PermissionCheck = require( '../middleware/PermissionCheck' )
const GetResource = require( '../middleware/GetResourceByType' )
Expand Down
3 changes: 1 addition & 2 deletions app/api/v1/comments/CommentPut.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const winston = require( 'winston' )
const chalk = require( 'chalk' )

const Comment = require( '../../../../models/Comment' )
const PermissionCheck = require( '../middleware/PermissionCheck' )
Expand All @@ -14,7 +13,7 @@ module.exports = function( req, res ) {
Comment.findOne( { _id: req.params.commentId } )
.then( resource => PermissionCheck( req.user, 'write', resource, Object.keys( req.body ) ) )
.then( resource => resource.set( req.body ).save() )
.then( result => {
.then( ( ) => {
return res.send( { success: true, message: 'Comment edited', fields: Object.keys( req.body ) } )
} )
.catch( err => {
Expand Down
37 changes: 16 additions & 21 deletions app/api/v1/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
const winston = require( 'winston' )
const chalk = require( 'chalk' )
const passport = require( 'passport' )

const tokenCheck = require( './middleware/TokenCheck' )

module.exports = function( app, express, urlRoot ) {
var r = new express.Router( )

Expand All @@ -14,7 +10,7 @@ module.exports = function( app, express, urlRoot ) {

//
// ACCOUNTS & USERS
//
//

// create a new account xxx
r.post( '/accounts/register', require( './accounts/UserCreate' ) )
Expand All @@ -25,7 +21,7 @@ module.exports = function( app, express, urlRoot ) {
// get profile xxx
r.get( '/accounts', mandatoryAuthorisation, require( './accounts/UserGet' ) )

// update profile xxx
// update profile xxx
r.put( '/accounts', mandatoryAuthorisation, require( './accounts/UserPut' ) )

// get other user's display profile xxx
Expand All @@ -35,9 +31,9 @@ module.exports = function( app, express, urlRoot ) {
r.post( '/accounts/search', mandatoryAuthorisation, require( './accounts/UserSearch' ) )


//
//
// CLIENTS
//
//

// create a new client xxx
r.post( '/clients', optionalAuthorisation, require( './clients/ClientPost' ) )
Expand All @@ -54,9 +50,9 @@ module.exports = function( app, express, urlRoot ) {
// delete a client / perm check 'delete' xxx
r.delete( '/clients/:clientId', mandatoryAuthorisation, require( './clients/ClientDelete' ) )

//
// STREAMS
//
//
// STREAMS
//

// create a new stream xxx
r.post( '/streams', mandatoryAuthorisation, require( './streams/StreamPost' ) )
Expand Down Expand Up @@ -84,8 +80,8 @@ module.exports = function( app, express, urlRoot ) {


//
// OBJECTS
//
// OBJECTS
//

// Create an object or more!
r.post( '/objects', mandatoryAuthorisation, require( './objects/ObjectPost' ) )
Expand All @@ -106,9 +102,9 @@ module.exports = function( app, express, urlRoot ) {
r.delete( '/objects/:objectId', mandatoryAuthorisation, require( './objects/ObjectDelete' ) )


//
//
// COMMENTS
//
//

// get user's comments
r.get( '/comments', mandatoryAuthorisation, require( './comments/CommentGetAll' ) )
Expand All @@ -132,9 +128,9 @@ module.exports = function( app, express, urlRoot ) {
r.delete( '/comments/:commentId', mandatoryAuthorisation, require( './comments/CommentDelete' ) )


//
// PROJECTS
//
//
// PROJECTS
//

// create a project xxx
r.post( '/projects', mandatoryAuthorisation, require( './projects/ProjectPost' ) )
Expand All @@ -158,17 +154,16 @@ module.exports = function( app, express, urlRoot ) {

// generate routes doc
let routes = [ ]
let count = 1
r.stack.forEach( ( middleware ) => {
if ( middleware.route )
routes.push( Object.keys( middleware.route.methods ).map( m => m.toUpperCase( ) ) + ': /api' + middleware.route.path )
} )

let serverDescription = {
serverName: process.env.SERVER_NAME,
maxRequestSize: process.env.REQ_SIZE
}

r.get( '/', ( req, res ) => {
serverDescription.routes = routes
serverDescription.version = '1.x.x'
Expand Down
6 changes: 1 addition & 5 deletions app/api/v1/middleware/PrepareQuery.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const winston = require( 'winston' )
const chalk = require( 'chalk' )
const q2m = require( 'query-to-mongo' )

/*
Expand All @@ -10,15 +8,13 @@ let enforcedFields = [ 'type', 'private', 'canRead', 'canWrite', 'owner' ]

module.exports = ( q ) => {
let query = q2m( q )
let isHacker = false;
if ( query.options.fields ) {
if ( q.omit === undefined ) {
if ( q.omit === undefined ) { // TODO: check this makes sense - should it be query.options.omit?
enforcedFields.forEach( field => query.options.fields[ field ] = 1 )
return query
}
enforcedFields.forEach( field => {
if ( query.options.fields[ field ] != undefined ) {
isHacker = true
delete query.options.fields[ field ]
}
} )
Expand Down
6 changes: 2 additions & 4 deletions app/api/v1/objects/ObjectDelete.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict'
const winston = require( 'winston' )
const passport = require( 'passport' )
const chalk = require( 'chalk' )

const SpeckleObject = require( '../../../../models/SpeckleObject' )
const PermissionCheck = require( '../middleware/PermissionCheck' )
Expand All @@ -15,12 +13,12 @@ module.exports = ( req, res ) => {
SpeckleObject.findOne( { _id: req.params.objectId } )
.then( obj => PermissionCheck( req.user, 'delete', obj ) )
.then( obj => obj.remove() )
.then( result => {
.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() } )
})
})
}
3 changes: 0 additions & 3 deletions app/api/v1/objects/ObjectPost.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
const winston = require( 'winston' )
const chalk = require( 'chalk' )
const _ = require( 'lodash' )

const SpeckleObject = require( '../../../../models/SpeckleObject' )
const BulkObjectSave = require( '../middleware/BulkObjectSave' )

module.exports = ( req, res ) => {
Expand Down
3 changes: 1 addition & 2 deletions app/api/v1/objects/ObjectPut.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const winston = require( 'winston' )
const chalk = require( 'chalk' )

const SpeckleObject = require( '../../../../models/SpeckleObject' )
const PermissionCheck = require( '../middleware/PermissionCheck' )
Expand All @@ -12,7 +11,7 @@ module.exports = ( req, res ) => {
SpeckleObject.findOne( { _id: req.params.objectId } )
.then( result => PermissionCheck( req.user, 'write', result, Object.keys( req.body ) ) )
.then( result => result.set( req.body ).save( ) )
.then( result => {
.then( ( ) => {
res.send( { success: true, message: 'Object updated.' } )
} )
.catch( err => {
Expand Down
Loading

0 comments on commit c43e678

Please sign in to comment.