From 8e4ca4e5f5995a60113b1aa179ef4aec64f03c1c Mon Sep 17 00:00:00 2001 From: Shivam Arora Date: Mon, 4 Jun 2018 23:46:05 +0530 Subject: [PATCH 1/3] Stack and User Almost ready --- stackle_api/app/lib/validator.js | 38 +++++++-- stackle_api/app/models/stack.js | 108 +++++++++++++++++++++++- stackle_api/app/models/user.js | 137 +++++++++++++++++++++++++++---- stackle_api/app/routes.js | 112 +++++++++++-------------- stackle_api/app/routes/stack.js | 45 ++++++++++ stackle_api/app/routes/user.js | 35 ++++++++ stackle_api/server.js | 7 +- 7 files changed, 389 insertions(+), 93 deletions(-) create mode 100644 stackle_api/app/routes/stack.js create mode 100644 stackle_api/app/routes/user.js diff --git a/stackle_api/app/lib/validator.js b/stackle_api/app/lib/validator.js index 198f61c..fa52919 100644 --- a/stackle_api/app/lib/validator.js +++ b/stackle_api/app/lib/validator.js @@ -44,6 +44,18 @@ Validator.prototype.validateGetPost = function() { return this.input; }; + +Validator.prototype.validateUserId = function() { + if (!this.input) { throw new Error('Input is undefined'); } + + if (!Object.keys(this.input).length) { throw new Error('Empty Object has been passed'); } + + if (!!!~Object.keys(this.input).indexOf('userId')) { throw new Error('Attribute userId is missing'); } + + return this.input; +}; + + Validator.prototype.validateDeletePost = function() { if (!this.input) { throw new Error('Input is undefined'); } @@ -84,6 +96,17 @@ Validator.prototype.validateGetOrganisationDetails = function() { return this.input; }; + +Validator.prototype.validateStackId = function() { + if (!this.input) { throw new Error('Input is undefined'); } + + if (!Object.keys(this.input).length) { throw new Error('Empty Object has been passed'); } + + if (!!!~Object.keys(this.input).indexOf('stackId')) { throw new Error('Attribute stackId is missing'); } + + return this.input; +}; + //Validating PostId Validator.prototype.validateCommentOnPost = function() { if (!this.input) { throw new Error('Input is undefined'); } @@ -155,9 +178,9 @@ Validator.prototype.validateCreateStack = function() { if (!!!~Object.keys(this.input).indexOf('stackleUrl')) { throw new Error('Attribute stackleUrl is missing'); } - if (!!!~Object.keys(this.input).indexOf('githubUrl')) { throw new Error('Attribute githubUrl is missing'); } + // if (!!!~Object.keys(this.input).indexOf('githubUrl')) { throw new Error('Attribute githubUrl is missing'); } - if (!!!~Object.keys(this.input).indexOf('created_user')) { throw new Error('Attribute created_user is missing'); } + if (!!!~Object.keys(this.input).indexOf('createdUser')) { throw new Error('Attribute createdUser is missing'); } return this.input; }; @@ -177,7 +200,7 @@ Validator.prototype.validateUserSubscribeStack = function() { if (!Object.keys(this.input).length) { throw new Error('Empty Object has been passed'); } - if (!!!~Object.keys(this.input).indexOf('stackName')) { throw new Error('Attribute stackName is missing'); } + if (!!!~Object.keys(this.input).indexOf('stackId')) { throw new Error('Attribute stackId is missing'); } if (!!!~Object.keys(this.input).indexOf('userId')) { throw new Error('Attribute userId is missing'); } @@ -199,14 +222,13 @@ Validator.prototype.validateCreateNewUser = function() { if (!Object.keys(this.input).length) { throw new Error('Empty Object has been passed'); } - if (!!!~Object.keys(this.input).indexOf('subscribed_stacks')) - { throw new Error('Attribute subscribed_stacks is missing'); } - - if (!!!~Object.keys(this.input).indexOf('gitlab')) { throw new Error('Attribute gitlab is missing'); } + if (!!!~Object.keys(this.input).indexOf('token')) { throw new Error('Attribute token is missing'); } if (!!!~Object.keys(this.input).indexOf('userId')) { throw new Error('Attribute userId is missing'); } - if (!!!~Object.keys(this.input).indexOf('github')) { throw new Error('Attribute github is missing'); } + if (!!!~Object.keys(this.input).indexOf('email')) { throw new Error('Attribute email is missing'); } + + if (!!!~Object.keys(this.input).indexOf('name')) { throw new Error('Attribute name is missing'); } return this.input; }; diff --git a/stackle_api/app/models/stack.js b/stackle_api/app/models/stack.js index 5a4b4d7..9ac4696 100644 --- a/stackle_api/app/models/stack.js +++ b/stackle_api/app/models/stack.js @@ -4,11 +4,111 @@ const returnWithResponse = require('../lib/returnWithResponse'); const stackSchema = mongoose.Schema({ - name: { type: String, required: true }, + name: { type: String, required: true, unique: true}, description: { type: String, required: true }, - stackleUrl: { type: String, required: true }, + stackleUrl: { type: String, required: true, unique: true}, githubUrl: String, - createdUser: { type: String, required: true } + createdUser: { type: String, required: true, unique: false} }); -module.exports = mongoose.model('Stack', stackSchema); \ No newline at end of file + +//create a stack +stackSchema.statics.createStack = function(request, response){ + try { + const validator = new Validator(request.body); + const input = validator.validateCreateStack(); + console.log('Input : ', input); + const stack = new Stack(input); + stack.save((error, insertedStack) => { + if (error) { + return returnWithResponse.configureReturnData({ status: 400, success: false, result: error }, response); + } + + return returnWithResponse.configureReturnData({ status: 200, success: true, result: insertedStack._id }, response); + }); + } catch (validationError) { + return returnWithResponse.configureReturnData({ status: 502, success: false, result: validationError.toString() }, response); + } +} + +//to get All stacks +stackSchema.statics.getAll = function(request, response){ + this.find({}, (error, stacksDetails) => { + if (error) { + return returnWithResponse.configureReturnData({ status: 400, success: false, result: error }, response); + } + + return returnWithResponse.configureReturnData({ status: 200, success: true, result: stacksDetails }, response); + }); +} + + +//to get stack by ID +stackSchema.statics.getByName = function(request, response){ + try { + const validator = new Validator(request.params); + const input = validator.validateGetOrganisationDetails(); + Stack.findOne({ name: input.organisationName }, (error, organisationDetails) => { + if (error) { + return returnWithResponse.configureReturnData({ status: 400, success: false, result: error }, response); + } + + return returnWithResponse.configureReturnData({ status: 200, success: true, result: organisationDetails }, response); + }); + } catch (validationError) { + return returnWithResponse.configureReturnData({ status: 502, success: false, result: validationError.toString() }, response); + } +} + +stackSchema.statics.getById = function(request, response){ + try { + const validator = new Validator(request.params); + const input = validator.validateStackId(); + Stack.findOne({ _id: input.stackId }, (error, organisationDetails) => { + if (error) { + return returnWithResponse.configureReturnData({ status: 400, success: false, result: error }, response); + } + + return returnWithResponse.configureReturnData({ status: 200, success: true, result: organisationDetails }, response); + }); + } catch (validationError) { + return returnWithResponse.configureReturnData({ status: 502, success: false, result: validationError.toString() }, response); + } +} + + + +stackSchema.statics.deleteById = function(request, response){ + try { + const validator = new Validator(request.params); + const input = validator.validateStackId(); + + this.remove({_id: input.stackId}, function(err){ + if(err) + return returnWithResponse.configureReturnData({ status: 400, success: false, result: err }, response); + + return returnWithResponse.configureReturnData({ status: 200, success: true, result: `Stack data removed with id : ${input.stackId}` }, response); + + }); + } + catch (validationError) { + return returnWithResponse.configureReturnData({ status: 502, success: false, result: validationError.toString() }, response); + } +} + + +//to delete all post +stackSchema.statics.clearAll = function(request, response){ + this.remove({}, function(err){ + if(err) + return returnWithResponse.configureReturnData({ status: 400, success: false, result: err }, response); + + + return returnWithResponse.configureReturnData({ status: 200, success: true, result: `All Stack data removed.` }, response); + + }); +} + + +const Stack = mongoose.model('Stack', stackSchema); +module.exports = Stack; \ No newline at end of file diff --git a/stackle_api/app/models/user.js b/stackle_api/app/models/user.js index 1698cf3..9d510e9 100644 --- a/stackle_api/app/models/user.js +++ b/stackle_api/app/models/user.js @@ -4,20 +4,127 @@ const returnWithResponse = require('../lib/returnWithResponse'); const userSchema = mongoose.Schema({ - userId: String, - github: { - id: String, - token: String, - email: String, - name: String - }, - gitlab: { - id: String, - token: String, - email: String, - name: String - }, - subscribedStacks: [] + userId: {type: String, required: true, unique: true}, + token: {type: String, required: true, unique: true}, + email: {type: String, required: true, unique: true}, + name: {type: String, required: true}, + subscribedStacks: [{type: mongoose.Schema.Types.ObjectId, ref: 'Stack'}] }); -module.exports = mongoose.model('User', userSchema); \ No newline at end of file +// create a user +userSchema.statics.createUser = function(request, response){ + try { + const validator = new Validator(request.body); + const input = validator.validateCreateNewUser(); + const user = new User(input); + user.save(function (error, insertedUser) { + if (error) { + return returnWithResponse.configureReturnData({ status: 400, success: false, result: error }, response); + } + + return returnWithResponse.configureReturnData({ status: 200, success: true, result: `${insertedUser.userId} user created` }, response); + }); + } catch (validationError) { + return returnWithResponse.configureReturnData({ status: 502, success: false, result: validationError.toString() }, response); + } +} + +//get All user +userSchema.statics.getAll = function(request, response){ + this.find({}).populate('subscribedStacks').exec((error, data) => { + if (error) { + return returnWithResponse.configureReturnData({ status: 400, success: false, result: error }, response); + } + return returnWithResponse.configureReturnData({ status: 200, success: true, result: data }, response); + }); +} + +//get User by userId +userSchema.statics.getById = function(request, response){ + try { + const validator = new Validator(request.params); + const input = validator.validateUserId(); + this.findOne({ userId: input.userId }).populate('subscribedStacks').exec((error, data) => { + if (error) { + return returnWithResponse.configureReturnData({ status: 400, success: false, result: error }, response); + } + + if(!data) + return returnWithResponse.configureReturnData({ status: 400, success: false, result: `User: ${input.userId} not found`}, response); + + + return returnWithResponse.configureReturnData({ status: 200, success: true, result: data }, response); + }); + } catch (validationError) { + return returnWithResponse.configureReturnData({ status: 502, success: false, result: validationError.toString() }, response); + } +} + +userSchema.statics.getStacks = function(request, response){ + try { + const validator = new Validator(request.params); + const input = validator.validateUserId(); + this.findOne({ userId: input.userId }).populate('subscribedStacks').exec((error, data) => { + if (error) { + return returnWithResponse.configureReturnData({ status: 400, success: false, result: error }, response); + } + + if(!data) + return returnWithResponse.configureReturnData({ status: 400, success: false, result: `User: ${input.userId} not found`}, response); + + + return returnWithResponse.configureReturnData({ status: 200, success: true, result: data.subscribedStacks }, response); + }); + } catch (validationError) { + return returnWithResponse.configureReturnData({ status: 502, success: false, result: validationError.toString() }, response); + } +} + +//subscribe stack +userSchema.statics.subscribe = function(request, response){ + try { + const validator = new Validator(request.body); + const input = validator.validateUserSubscribeStack(); + + + this.findOne({ userId: input.userId }, (error, result) => { + if (error) { + return returnWithResponse.configureReturnData({ status: 400, success: false, result: error }, response); + } + + if(!result) + return returnWithResponse.configureReturnData({ status: 400, success: false, result: `User: ${input.userId} not found`}, response); + + var stacks = result.subscribedStacks; + var check = stacks.indexOf(input.stackId); + if(check === -1){ + result.subscribedStacks.push(input.stackId); + result.save(); + return returnWithResponse.configureReturnData({ status: 200, success: true, result: `user ${input.userId} subscribed to stack : ${input.stackId} `}, response); + } + else{ + return returnWithResponse.configureReturnData({ status: 200, success: false, result: `user ${input.userId} Already subscribed to stack : ${input.stackId} `}, response); + } + + }); + + } catch (validationError) { + return returnWithResponse.configureReturnData({ status: 502, success: false, result: validationError.toString() }, response); + } +} + + +//delete all user +userSchema.statics.clearAll = function(request, response){ + this.remove({}, function(err){ + if(err) + return returnWithResponse.configureReturnData({ status: 400, success: false, result: err }, response); + + + return returnWithResponse.configureReturnData({ status: 200, success: true, result: `All User data removed.` }, response); + + }); +} + +const User = mongoose.model('User', userSchema); +module.exports = User; \ No newline at end of file diff --git a/stackle_api/app/routes.js b/stackle_api/app/routes.js index 205dbb9..c55e3bc 100644 --- a/stackle_api/app/routes.js +++ b/stackle_api/app/routes.js @@ -27,53 +27,53 @@ module.exports = function (app, db) { - // get a specific organisation - app.get('/api/org/:organisationName', function (request, response) { - try { - const validator = new Validator(request.params); - const input = validator.validateGetOrganisationDetails(); - Stack.find({ name: input.organisationName }, (error, organisationDetails) => { - if (error) { - return returnWithResponse.configureReturnData({ status: 400, success: false, result: error }, response); - } - - return returnWithResponse.configureReturnData({ status: 200, success: true, result: organisationDetails }, response); - }); - } catch (validationError) { - return returnWithResponse.configureReturnData({ status: 502, success: false, result: validationError }, response); - } - }); - - - // get all stacks (organisation) - app.get('/api/orgs', function (request, response) { - Stack.find({}, (error, stacksDetails) => { - if (error) { - return returnWithResponse.configureReturnData({ status: 400, success: false, result: error }, response); - } - - return returnWithResponse.configureReturnData({ status: 200, success: true, result: stacksDetails }, response); - }); - }); - - // create stack - app.post('/api/stack/create', function (request, response) { - try { - const validator = new Validator(request.body); - const input = validator.validateCreateStack(); - console.log('Input : ', input); - const stack = new Stack(input); - stack.save((error, insertedStack) => { - if (error) { - return returnWithResponse.configureReturnData({ status: 400, success: false, result: error }, response); - } - - return returnWithResponse.configureReturnData({ status: 200, success: true, result: insertedStack._id }, response); - }); - } catch (validationError) { - return returnWithResponse.configureReturnData({ status: 502, success: false, result: validationError }, response); - } - }); + // // get a specific organisation + // app.get('/api/org/:organisationName', function (request, response) { + // try { + // const validator = new Validator(request.params); + // const input = validator.validateGetOrganisationDetails(); + // Stack.find({ name: input.organisationName }, (error, organisationDetails) => { + // if (error) { + // return returnWithResponse.configureReturnData({ status: 400, success: false, result: error }, response); + // } + + // return returnWithResponse.configureReturnData({ status: 200, success: true, result: organisationDetails }, response); + // }); + // } catch (validationError) { + // return returnWithResponse.configureReturnData({ status: 502, success: false, result: validationError }, response); + // } + // }); + + + // // get all stacks (organisation) + // app.get('/api/orgs', function (request, response) { + // Stack.find({}, (error, stacksDetails) => { + // if (error) { + // return returnWithResponse.configureReturnData({ status: 400, success: false, result: error }, response); + // } + + // return returnWithResponse.configureReturnData({ status: 200, success: true, result: stacksDetails }, response); + // }); + // }); + + // // create stack + // app.post('/api/stack/create', function (request, response) { + // try { + // const validator = new Validator(request.body); + // const input = validator.validateCreateStack(); + // console.log('Input : ', input); + // const stack = new Stack(input); + // stack.save((error, insertedStack) => { + // if (error) { + // return returnWithResponse.configureReturnData({ status: 400, success: false, result: error }, response); + // } + + // return returnWithResponse.configureReturnData({ status: 200, success: true, result: insertedStack._id }, response); + // }); + // } catch (validationError) { + // return returnWithResponse.configureReturnData({ status: 502, success: false, result: validationError }, response); + // } + // }); // delete stack app.delete('api/delete/stack/:stackId', function (request, response) { @@ -123,24 +123,6 @@ module.exports = function (app, db) { } }); - // create user and retruning created user id - app.post('/api/newuser', function (request, response) { - try { - const validator = new Validator(request.body); - const input = validator.validateCreateNewUser(); - const user = new User(input); - user.save(function (error, insertedUser) { - if (error) { - return returnWithResponse.configureReturnData({ status: 400, success: false, result: error }, response); - } - - return returnWithResponse.configureReturnData({ status: 200, success: true, result: insertedUser._id }, response); - }); - } catch (validationError) { - return returnWithResponse.configureReturnData({ status: 502, success: false, result: validationError }, response); - } - }); - app.get('/api/notifications', function (request, response) { }); app.get('/*', function (request, response) { diff --git a/stackle_api/app/routes/stack.js b/stackle_api/app/routes/stack.js new file mode 100644 index 0000000..0182345 --- /dev/null +++ b/stackle_api/app/routes/stack.js @@ -0,0 +1,45 @@ +var express = require('express'); +var router = express.Router(); + +const Model = require('../models/stack'); + +//create a Stack + router.post('/create', function(request, response){ + Model.createStack(request, response); + }); + +//get All stacks + router.get('/all', function(request, response){ + Model.getAll(request, response); + }); + +//get stack by name + router.get('/name/:organisationName', function(request, response){ + Model.getByName(request, response); + }); + + +// Get stack by id + router.get('/id/:stackId', function(request, response){ + Model.getById(request, response); + }); + + + + +//Only for developer Mode. Never consume below two APIs + +//clear all data + router.delete('/all', function(request, response){ + Model.clearAll(request, response); + }); + +// Delete stack by id + router.delete('/:stackId', function(request, response){ + Model.deleteById(request, response); + }); + + + + +module.exports = router; diff --git a/stackle_api/app/routes/user.js b/stackle_api/app/routes/user.js new file mode 100644 index 0000000..dd3cc35 --- /dev/null +++ b/stackle_api/app/routes/user.js @@ -0,0 +1,35 @@ +var express = require('express'); +var router = express.Router(); +const userModel = require('../models/user'); + +//create a user + router.post('/create', function(request, response){ + userModel.createUser(request, response); + }); + +//get All users + router.get('/all', function(request, response){ + userModel.getAll(request, response); + }); + +//get current user + router.get('/:userId', function(request, response){ + userModel.getById(request, response); + }); + +//get list of subscribed stacks + router.get('/stacks/:userId', function(request,response){ + userModel.getStacks(request, response); + }); + +//subscribe a stack + router.post('/subscribe', function(request, response){ + userModel.subscribe(request, response); + }); + +//clear all data + router.delete('/all', function(request, response){ + userModel.clearAll(request, response); + }); + +module.exports = router; diff --git a/stackle_api/server.js b/stackle_api/server.js index a2dbb3a..5dd4d83 100644 --- a/stackle_api/server.js +++ b/stackle_api/server.js @@ -10,6 +10,8 @@ const db = mongoose.connection; const cors = require("cors"); const postRouter = require('./app/routes/post'); const commentRouter = require('./app/routes/comment'); +const userRouter = require('./app/routes/user'); +const stackRouter = require('./app/routes/stack'); app.use(morgan('dev')); // log every request to the console app.use(bodyParser.urlencoded({ 'extended': 'true' })); // parse application/x-www-form-urlencoded @@ -24,7 +26,10 @@ app.use('/', express.static(__dirname + '/')); //serving endpoint related to post using middleware app.use('/api/post', postRouter); -app.use('/api/comment', commentRouter); +app.use('/api/comment', commentRouter); +app.use('/api/user', userRouter); +app.use('/api/org', stackRouter); + var routes = require("./app/routes"); routes(app, db); From acc9616aca38fcac249d36996ae7287112f0052a Mon Sep 17 00:00:00 2001 From: Shivam Arora Date: Fri, 8 Jun 2018 22:13:51 +0530 Subject: [PATCH 2/3] User and Stack Routes Structured User and Stack Routes Structured --- stackle_api/app/lib/validator.js | 1 + stackle_api/app/models/stack.js | 9 ++- stackle_api/app/models/user.js | 33 +++++++++++ stackle_api/app/routes.js | 98 ------------------------------- stackle_api/app/routes/comment.js | 2 +- stackle_api/app/routes/post.js | 4 +- stackle_api/app/routes/stack.js | 2 - stackle_api/app/routes/user.js | 10 +++- 8 files changed, 50 insertions(+), 109 deletions(-) diff --git a/stackle_api/app/lib/validator.js b/stackle_api/app/lib/validator.js index fa52919..7a63ea6 100644 --- a/stackle_api/app/lib/validator.js +++ b/stackle_api/app/lib/validator.js @@ -207,6 +207,7 @@ Validator.prototype.validateUserSubscribeStack = function() { return this.input; }; + Validator.prototype.validateGetUserSubscribeStack = function() { if (!this.input) { throw new Error('Input is undefined'); } diff --git a/stackle_api/app/models/stack.js b/stackle_api/app/models/stack.js index 9ac4696..8962b26 100644 --- a/stackle_api/app/models/stack.js +++ b/stackle_api/app/models/stack.js @@ -42,8 +42,7 @@ stackSchema.statics.getAll = function(request, response){ }); } - -//to get stack by ID +//to get stack by Name stackSchema.statics.getByName = function(request, response){ try { const validator = new Validator(request.params); @@ -60,6 +59,7 @@ stackSchema.statics.getByName = function(request, response){ } } +//to get Stack by Id stackSchema.statics.getById = function(request, response){ try { const validator = new Validator(request.params); @@ -76,8 +76,9 @@ stackSchema.statics.getById = function(request, response){ } } +//Only For Developer Mode. - +//Delete Stack by ID stackSchema.statics.deleteById = function(request, response){ try { const validator = new Validator(request.params); @@ -96,7 +97,6 @@ stackSchema.statics.deleteById = function(request, response){ } } - //to delete all post stackSchema.statics.clearAll = function(request, response){ this.remove({}, function(err){ @@ -109,6 +109,5 @@ stackSchema.statics.clearAll = function(request, response){ }); } - const Stack = mongoose.model('Stack', stackSchema); module.exports = Stack; \ No newline at end of file diff --git a/stackle_api/app/models/user.js b/stackle_api/app/models/user.js index 9d510e9..723fca1 100644 --- a/stackle_api/app/models/user.js +++ b/stackle_api/app/models/user.js @@ -113,6 +113,39 @@ userSchema.statics.subscribe = function(request, response){ } } +//unsubscribe the user from stack +userSchema.statics.unsubscribe = function(request, response){ + try { + const validator = new Validator(request.body); + //validating userId and stackId in body + const input = validator.validateUserSubscribeStack(); + + this.findOne({ userId: input.userId }, (error, result) => { + if (error) { + return returnWithResponse.configureReturnData({ status: 400, success: false, result: error }, response); + } + + if(!result) + return returnWithResponse.configureReturnData({ status: 400, success: false, result: `User: ${input.userId} not found`}, response); + + var stacks = result.subscribedStacks; + var check = stacks.indexOf(input.stackId); + if(check === -1){ + return returnWithResponse.configureReturnData({ status: 200, success: false, result: `user ${input.userId} is not subscribed to stack : ${input.stackId} `}, response); + } + else{ + + stacks.splice(check,1); + result.save(); + return returnWithResponse.configureReturnData({ status: 200, success: true, result: `user ${input.userId} Unsubscribed to stack : ${input.stackId} `}, response); + } + + }); + + } catch (validationError) { + return returnWithResponse.configureReturnData({ status: 502, success: false, result: validationError.toString() }, response); + } +} //delete all user userSchema.statics.clearAll = function(request, response){ diff --git a/stackle_api/app/routes.js b/stackle_api/app/routes.js index c55e3bc..82ac1b1 100644 --- a/stackle_api/app/routes.js +++ b/stackle_api/app/routes.js @@ -25,104 +25,6 @@ module.exports = function (app, db) { return returnWithResponse.configureReturnData({ status: 501, success: false, result: 'Not Implemented' }, response); }); - - - // // get a specific organisation - // app.get('/api/org/:organisationName', function (request, response) { - // try { - // const validator = new Validator(request.params); - // const input = validator.validateGetOrganisationDetails(); - // Stack.find({ name: input.organisationName }, (error, organisationDetails) => { - // if (error) { - // return returnWithResponse.configureReturnData({ status: 400, success: false, result: error }, response); - // } - - // return returnWithResponse.configureReturnData({ status: 200, success: true, result: organisationDetails }, response); - // }); - // } catch (validationError) { - // return returnWithResponse.configureReturnData({ status: 502, success: false, result: validationError }, response); - // } - // }); - - - // // get all stacks (organisation) - // app.get('/api/orgs', function (request, response) { - // Stack.find({}, (error, stacksDetails) => { - // if (error) { - // return returnWithResponse.configureReturnData({ status: 400, success: false, result: error }, response); - // } - - // return returnWithResponse.configureReturnData({ status: 200, success: true, result: stacksDetails }, response); - // }); - // }); - - // // create stack - // app.post('/api/stack/create', function (request, response) { - // try { - // const validator = new Validator(request.body); - // const input = validator.validateCreateStack(); - // console.log('Input : ', input); - // const stack = new Stack(input); - // stack.save((error, insertedStack) => { - // if (error) { - // return returnWithResponse.configureReturnData({ status: 400, success: false, result: error }, response); - // } - - // return returnWithResponse.configureReturnData({ status: 200, success: true, result: insertedStack._id }, response); - // }); - // } catch (validationError) { - // return returnWithResponse.configureReturnData({ status: 502, success: false, result: validationError }, response); - // } - // }); - - // delete stack - app.delete('api/delete/stack/:stackId', function (request, response) { - const stackId = request.params.stackId; - Stack.remove({ _id: stackId }, (error, result) => { - if (error) { - return returnWithResponse.configureReturnData({ status: 400, success: false, result: error }, response); - } - return returnWithResponse.configureReturnData({ status: 200, success: true, result: `${stackId} was sucessfully deleted` }, - response); - }); - }); - - // user subscribing to an stack - app.post('/api/subscribe', function (request, response) { - try { - const validator = new Validator(request.body); - const input = validator.validateUserSubscribeStack(); - User.findOneAndUpdate({ userId: input.userId }, { $push: { subscribedStacks: input.stackName } }, (error, updatedResult) => { - if (error) { - return returnWithResponse.configureReturnData({ status: 400, success: false, result: error }, response); - } - - return returnWithResponse.configureReturnData({ status: 200, success: true, result: `${stackName} was sucessfully updated` }, - response); - }); - } catch (validationError) { - return returnWithResponse.configureReturnData({ status: 502, success: false, result: validationError }, response); - } - }); - - // getting subscribed stacks for a user - app.get('/api/stack/subscribed/:userId', function (request, response) { - try { - const validator = new Validator(request.params); - const input = validator.validateGetUserSubscribeStack(); - User.findOne({ userId: input.userId }, (error, userDetails) => { - if (error) { - return returnWithResponse.configureReturnData({ status: 400, success: false, result: error }, response); - } - - return returnWithResponse.configureReturnData({ status: 200, success: true, result: userDetails.subscribedStacks }, response); - }); - - } catch (validationError) { - return returnWithResponse.configureReturnData({ status: 502, success: false, result: validationError }, response); - } - }); - app.get('/api/notifications', function (request, response) { }); app.get('/*', function (request, response) { diff --git a/stackle_api/app/routes/comment.js b/stackle_api/app/routes/comment.js index b139970..3d14a16 100644 --- a/stackle_api/app/routes/comment.js +++ b/stackle_api/app/routes/comment.js @@ -15,7 +15,7 @@ const Comment = postModels.Comment; Model.getAllComments(request, response); }); -//to clear all comment +//to clear all comment - (only for developer mode) router.delete('/all', function(request, response){ Comment.deleteAll(request, response); }); diff --git a/stackle_api/app/routes/post.js b/stackle_api/app/routes/post.js index fbf01d8..4716e4a 100644 --- a/stackle_api/app/routes/post.js +++ b/stackle_api/app/routes/post.js @@ -28,12 +28,12 @@ const Post = postModels.Post; Post.getAllByOrg(request, response); }); -//to clear model +//to clear model - (only for developer mode) router.delete('/all', function(request, response){ Post.deleteAll(request, response); }); -//to delete a post by ID +//to delete a post by ID - (only for developer mode) router.delete('/:postId', function (request, response) { Post.deleteById(request, response); }); diff --git a/stackle_api/app/routes/stack.js b/stackle_api/app/routes/stack.js index 0182345..62e4b65 100644 --- a/stackle_api/app/routes/stack.js +++ b/stackle_api/app/routes/stack.js @@ -25,8 +25,6 @@ const Model = require('../models/stack'); }); - - //Only for developer Mode. Never consume below two APIs //clear all data diff --git a/stackle_api/app/routes/user.js b/stackle_api/app/routes/user.js index dd3cc35..5664187 100644 --- a/stackle_api/app/routes/user.js +++ b/stackle_api/app/routes/user.js @@ -25,7 +25,15 @@ const userModel = require('../models/user'); //subscribe a stack router.post('/subscribe', function(request, response){ userModel.subscribe(request, response); - }); + }); + +//unsubscribe a stack + router.post('/unsubscribe', function(request, response){ + userModel.unsubscribe(request, response); + }); + + +// only for developer mode dont consume below APIs //clear all data router.delete('/all', function(request, response){ From bd8650246755e72eda7d13077bc3f27c052768c2 Mon Sep 17 00:00:00 2001 From: Shivam Arora Date: Thu, 14 Jun 2018 11:51:40 +0530 Subject: [PATCH 3/3] Changes made / User and Stack Structured 1. Add option to db.connect if mongoose version is less than 5 2. Post create validation improved 3. un-necessary Console.log removed --- stackle_api/app/lib/validator.js | 2 +- stackle_api/app/models/post.js | 2 - stackle_api/app/models/stack.js | 1 - stackle_api/config/database.js | 7 + stackle_api/package-lock.json | 624 +++++++++++++++++++++++++++---- stackle_api/package.json | 2 +- stackle_api/server.js | 8 +- 7 files changed, 561 insertions(+), 85 deletions(-) diff --git a/stackle_api/app/lib/validator.js b/stackle_api/app/lib/validator.js index 7a63ea6..a91eb46 100644 --- a/stackle_api/app/lib/validator.js +++ b/stackle_api/app/lib/validator.js @@ -22,7 +22,7 @@ Validator.prototype.validateAddingPost = function() { if (!!!~Object.keys(this.input).indexOf('tags')) { throw new Error('Attribute tags is missing'); } - if (!!!~Object.keys(this.input).indexOf('link_issue')) { throw new Error('Attribute link_issue is missing'); } + if (!!!~Object.keys(this.input).indexOf('linkIssue')) { throw new Error('Attribute link_issue is missing'); } if (!!!~Object.keys(this.input).indexOf('user')) { throw new Error('Attribute user is missing'); } diff --git a/stackle_api/app/models/post.js b/stackle_api/app/models/post.js index cea9ae1..d963620 100644 --- a/stackle_api/app/models/post.js +++ b/stackle_api/app/models/post.js @@ -123,7 +123,6 @@ postSchema.statics.getAllByOrg = function(request, response){ } } - //Comment on a post postSchema.statics.commentById = function(request, response){ try { @@ -156,7 +155,6 @@ postSchema.statics.commentById = function(request, response){ } } - //get All comments for a single post postSchema.statics.getAllComments = function(request, response){ try { diff --git a/stackle_api/app/models/stack.js b/stackle_api/app/models/stack.js index 8962b26..5aff7ac 100644 --- a/stackle_api/app/models/stack.js +++ b/stackle_api/app/models/stack.js @@ -17,7 +17,6 @@ stackSchema.statics.createStack = function(request, response){ try { const validator = new Validator(request.body); const input = validator.validateCreateStack(); - console.log('Input : ', input); const stack = new Stack(input); stack.save((error, insertedStack) => { if (error) { diff --git a/stackle_api/config/database.js b/stackle_api/config/database.js index cc605f3..a830c60 100644 --- a/stackle_api/config/database.js +++ b/stackle_api/config/database.js @@ -1,6 +1,13 @@ module.exports = { url : process.env.LOCAL_DB || "mongodb://localhost", alturl : "mongodb://ordinary:H3ll0w0rld@ds149201.mlab.com:49201/stackle", + option: function(version){ + var opt ; + if(version < '5'){ + opt = { useMongoClient: true }; + } + return opt; + } }; /* diff --git a/stackle_api/package-lock.json b/stackle_api/package-lock.json index d554bcb..be8db7a 100644 --- a/stackle_api/package-lock.json +++ b/stackle_api/package-lock.json @@ -141,11 +141,11 @@ "integrity": "sha1-WWZ/QfrdTyDMvCu5a41Pf3jsA2c=" }, "async": { - "version": "2.1.4", - "resolved": "https://registry.npmjs.org/async/-/async-2.1.4.tgz", - "integrity": "sha1-LSFgx3iAMuTdbL4lAvH5osj2zeQ=", + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/async/-/async-2.6.1.tgz", + "integrity": "sha512-fNEiL2+AZt6AlAw/29Cr0UDe4sRAHCpEHh54WMz+Bb7QfNcFw4h3loofyJpLeQs4Yx7yuqu/2dLgM5hKOs6HlQ==", "requires": { - "lodash": "4.17.4" + "lodash": "4.17.10" } }, "async-each": { @@ -270,6 +270,11 @@ "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-1.10.0.tgz", "integrity": "sha1-muuabF6IY4qtFx4Wf1kAq+JINdA=" }, + "bluebird": { + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.0.tgz", + "integrity": "sha1-eRQg1/VR7qKJdFOop3ZT+WYG1nw=" + }, "body-parser": { "version": "1.18.2", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.18.2.tgz", @@ -336,9 +341,9 @@ } }, "bson": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/bson/-/bson-1.0.4.tgz", - "integrity": "sha1-k8ENOeqltYQVy8QFLz5T5WKwtyw=" + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/bson/-/bson-1.0.9.tgz", + "integrity": "sha512-IQX9/h7WdMBIW/q/++tGd+emQr0XMdeZ6icnT/74Xk9fnabWn+gZgpE+9V+gujL3hhJOoNrnDVY7tWdzc7NUTg==" }, "buffer-equal-constant-time": { "version": "1.0.1", @@ -1175,6 +1180,468 @@ "resolved": "https://registry.npmjs.org/from/-/from-0.1.7.tgz", "integrity": "sha1-g8YK/Fi5xWmXAH7Rp2izqzA6RP4=" }, + "fsevents": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.2.4.tgz", + "integrity": "sha512-z8H8/diyk76B7q5wg+Ud0+CqzcAF3mBBI/bA5ne5zrRUUIvNkJY//D3BqyH571KuAC4Nr7Rw7CjWX4r0y9DvNg==", + "optional": true, + "requires": { + "nan": "2.10.0", + "node-pre-gyp": "0.10.0" + }, + "dependencies": { + "abbrev": { + "version": "1.1.1", + "bundled": true, + "optional": true + }, + "ansi-regex": { + "version": "2.1.1", + "bundled": true + }, + "aproba": { + "version": "1.2.0", + "bundled": true, + "optional": true + }, + "are-we-there-yet": { + "version": "1.1.4", + "bundled": true, + "optional": true, + "requires": { + "delegates": "1.0.0", + "readable-stream": "2.3.6" + } + }, + "balanced-match": { + "version": "1.0.0", + "bundled": true + }, + "brace-expansion": { + "version": "1.1.11", + "bundled": true, + "requires": { + "balanced-match": "1.0.0", + "concat-map": "0.0.1" + } + }, + "chownr": { + "version": "1.0.1", + "bundled": true, + "optional": true + }, + "code-point-at": { + "version": "1.1.0", + "bundled": true + }, + "concat-map": { + "version": "0.0.1", + "bundled": true + }, + "console-control-strings": { + "version": "1.1.0", + "bundled": true + }, + "core-util-is": { + "version": "1.0.2", + "bundled": true, + "optional": true + }, + "debug": { + "version": "2.6.9", + "bundled": true, + "optional": true, + "requires": { + "ms": "2.0.0" + } + }, + "deep-extend": { + "version": "0.5.1", + "bundled": true, + "optional": true + }, + "delegates": { + "version": "1.0.0", + "bundled": true, + "optional": true + }, + "detect-libc": { + "version": "1.0.3", + "bundled": true, + "optional": true + }, + "fs-minipass": { + "version": "1.2.5", + "bundled": true, + "optional": true, + "requires": { + "minipass": "2.2.4" + } + }, + "fs.realpath": { + "version": "1.0.0", + "bundled": true, + "optional": true + }, + "gauge": { + "version": "2.7.4", + "bundled": true, + "optional": true, + "requires": { + "aproba": "1.2.0", + "console-control-strings": "1.1.0", + "has-unicode": "2.0.1", + "object-assign": "4.1.1", + "signal-exit": "3.0.2", + "string-width": "1.0.2", + "strip-ansi": "3.0.1", + "wide-align": "1.1.2" + } + }, + "glob": { + "version": "7.1.2", + "bundled": true, + "optional": true, + "requires": { + "fs.realpath": "1.0.0", + "inflight": "1.0.6", + "inherits": "2.0.3", + "minimatch": "3.0.4", + "once": "1.4.0", + "path-is-absolute": "1.0.1" + } + }, + "has-unicode": { + "version": "2.0.1", + "bundled": true, + "optional": true + }, + "iconv-lite": { + "version": "0.4.21", + "bundled": true, + "optional": true, + "requires": { + "safer-buffer": "2.1.2" + } + }, + "ignore-walk": { + "version": "3.0.1", + "bundled": true, + "optional": true, + "requires": { + "minimatch": "3.0.4" + } + }, + "inflight": { + "version": "1.0.6", + "bundled": true, + "optional": true, + "requires": { + "once": "1.4.0", + "wrappy": "1.0.2" + } + }, + "inherits": { + "version": "2.0.3", + "bundled": true + }, + "ini": { + "version": "1.3.5", + "bundled": true, + "optional": true + }, + "is-fullwidth-code-point": { + "version": "1.0.0", + "bundled": true, + "requires": { + "number-is-nan": "1.0.1" + } + }, + "isarray": { + "version": "1.0.0", + "bundled": true, + "optional": true + }, + "minimatch": { + "version": "3.0.4", + "bundled": true, + "requires": { + "brace-expansion": "1.1.11" + } + }, + "minimist": { + "version": "0.0.8", + "bundled": true + }, + "minipass": { + "version": "2.2.4", + "bundled": true, + "requires": { + "safe-buffer": "5.1.1", + "yallist": "3.0.2" + } + }, + "minizlib": { + "version": "1.1.0", + "bundled": true, + "optional": true, + "requires": { + "minipass": "2.2.4" + } + }, + "mkdirp": { + "version": "0.5.1", + "bundled": true, + "requires": { + "minimist": "0.0.8" + } + }, + "ms": { + "version": "2.0.0", + "bundled": true, + "optional": true + }, + "needle": { + "version": "2.2.0", + "bundled": true, + "optional": true, + "requires": { + "debug": "2.6.9", + "iconv-lite": "0.4.21", + "sax": "1.2.4" + } + }, + "node-pre-gyp": { + "version": "0.10.0", + "bundled": true, + "optional": true, + "requires": { + "detect-libc": "1.0.3", + "mkdirp": "0.5.1", + "needle": "2.2.0", + "nopt": "4.0.1", + "npm-packlist": "1.1.10", + "npmlog": "4.1.2", + "rc": "1.2.7", + "rimraf": "2.6.2", + "semver": "5.5.0", + "tar": "4.4.1" + } + }, + "nopt": { + "version": "4.0.1", + "bundled": true, + "optional": true, + "requires": { + "abbrev": "1.1.1", + "osenv": "0.1.5" + } + }, + "npm-bundled": { + "version": "1.0.3", + "bundled": true, + "optional": true + }, + "npm-packlist": { + "version": "1.1.10", + "bundled": true, + "optional": true, + "requires": { + "ignore-walk": "3.0.1", + "npm-bundled": "1.0.3" + } + }, + "npmlog": { + "version": "4.1.2", + "bundled": true, + "optional": true, + "requires": { + "are-we-there-yet": "1.1.4", + "console-control-strings": "1.1.0", + "gauge": "2.7.4", + "set-blocking": "2.0.0" + } + }, + "number-is-nan": { + "version": "1.0.1", + "bundled": true + }, + "object-assign": { + "version": "4.1.1", + "bundled": true, + "optional": true + }, + "once": { + "version": "1.4.0", + "bundled": true, + "requires": { + "wrappy": "1.0.2" + } + }, + "os-homedir": { + "version": "1.0.2", + "bundled": true, + "optional": true + }, + "os-tmpdir": { + "version": "1.0.2", + "bundled": true, + "optional": true + }, + "osenv": { + "version": "0.1.5", + "bundled": true, + "optional": true, + "requires": { + "os-homedir": "1.0.2", + "os-tmpdir": "1.0.2" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "bundled": true, + "optional": true + }, + "process-nextick-args": { + "version": "2.0.0", + "bundled": true, + "optional": true + }, + "rc": { + "version": "1.2.7", + "bundled": true, + "optional": true, + "requires": { + "deep-extend": "0.5.1", + "ini": "1.3.5", + "minimist": "1.2.0", + "strip-json-comments": "2.0.1" + }, + "dependencies": { + "minimist": { + "version": "1.2.0", + "bundled": true, + "optional": true + } + } + }, + "readable-stream": { + "version": "2.3.6", + "bundled": true, + "optional": true, + "requires": { + "core-util-is": "1.0.2", + "inherits": "2.0.3", + "isarray": "1.0.0", + "process-nextick-args": "2.0.0", + "safe-buffer": "5.1.1", + "string_decoder": "1.1.1", + "util-deprecate": "1.0.2" + } + }, + "rimraf": { + "version": "2.6.2", + "bundled": true, + "optional": true, + "requires": { + "glob": "7.1.2" + } + }, + "safe-buffer": { + "version": "5.1.1", + "bundled": true + }, + "safer-buffer": { + "version": "2.1.2", + "bundled": true, + "optional": true + }, + "sax": { + "version": "1.2.4", + "bundled": true, + "optional": true + }, + "semver": { + "version": "5.5.0", + "bundled": true, + "optional": true + }, + "set-blocking": { + "version": "2.0.0", + "bundled": true, + "optional": true + }, + "signal-exit": { + "version": "3.0.2", + "bundled": true, + "optional": true + }, + "string-width": { + "version": "1.0.2", + "bundled": true, + "requires": { + "code-point-at": "1.1.0", + "is-fullwidth-code-point": "1.0.0", + "strip-ansi": "3.0.1" + } + }, + "string_decoder": { + "version": "1.1.1", + "bundled": true, + "optional": true, + "requires": { + "safe-buffer": "5.1.1" + } + }, + "strip-ansi": { + "version": "3.0.1", + "bundled": true, + "requires": { + "ansi-regex": "2.1.1" + } + }, + "strip-json-comments": { + "version": "2.0.1", + "bundled": true, + "optional": true + }, + "tar": { + "version": "4.4.1", + "bundled": true, + "optional": true, + "requires": { + "chownr": "1.0.1", + "fs-minipass": "1.2.5", + "minipass": "2.2.4", + "minizlib": "1.1.0", + "mkdirp": "0.5.1", + "safe-buffer": "5.1.1", + "yallist": "3.0.2" + } + }, + "util-deprecate": { + "version": "1.0.2", + "bundled": true, + "optional": true + }, + "wide-align": { + "version": "1.1.2", + "bundled": true, + "optional": true, + "requires": { + "string-width": "1.0.2" + } + }, + "wrappy": { + "version": "1.0.2", + "bundled": true + }, + "yallist": { + "version": "3.0.2", + "bundled": true + } + } + }, "get-stream": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", @@ -1661,6 +2128,11 @@ "safe-buffer": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz" } }, + "kareem": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/kareem/-/kareem-2.2.1.tgz", + "integrity": "sha512-xpDFy8OxkFM+vK6pXy6JmH92ibeEFUuDWzas5M9L7MzVmHW3jzwAHxodCPV/BYkf4A31bVDLyonrMfp9RXb/oA==" + }, "kind-of": { "version": "3.2.2", "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz", @@ -1688,9 +2160,9 @@ "integrity": "sha1-/sfervF+fDoKVeHaBCgD4l2RdF0=" }, "lodash": { - "version": "4.17.4", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.4.tgz", - "integrity": "sha1-eCA6TRwyiuHYbcpkYONptX9AVa4=" + "version": "4.17.10", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz", + "integrity": "sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg==" }, "lodash.get": { "version": "4.4.2", @@ -1942,16 +2414,33 @@ } } }, + "mongodb": { + "version": "3.0.9", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.0.9.tgz", + "integrity": "sha512-2NJzruJu15/1YF6+H55f1wfLQb1M6/+hU96+L5sPv07PDZDPvZEDJBtCjFQorpbW9D2aqsem7mFVUKPhVwwRog==", + "requires": { + "mongodb-core": "3.0.8" + } + }, + "mongodb-core": { + "version": "3.0.8", + "resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-3.0.8.tgz", + "integrity": "sha512-dFxfhH9N7ohuQnINyIl6dqEF8sYOE0WKuymrFf3L3cipJNrx+S8rAbNOTwa00/fuJCjBMJNFsaA+R2N16//UIw==", + "requires": { + "bson": "1.0.9", + "require_optional": "1.0.1" + } + }, "mongoose": { - "version": "5.0.17", - "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-5.0.17.tgz", - "integrity": "sha512-RV1WBQhzW7oOhStR+s7LQYfgQWTJm4hgmU3TqtgTiBCfnj5/sNliX2/SY+ef7tpIZRUqEBV5xITZdAlwQ6Ymdg==", + "version": "5.1.5", + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-5.1.5.tgz", + "integrity": "sha512-/bDtFRvWZclE4Fxw5ntofGA2Zm+lgJJw9WHZK4aWotVNK5MEDxrfPp+W/gk4whv0t4AO9JxmyAD4jfotjARSiA==", "requires": { - "async": "2.1.4", - "bson": "1.0.4", - "kareem": "2.0.7", + "async": "2.6.1", + "bson": "1.0.9", + "kareem": "2.2.1", "lodash.get": "4.4.2", - "mongodb": "3.0.7", + "mongodb": "3.0.9", "mongoose-legacy-pluralize": "1.0.2", "mpath": "0.4.1", "mquery": "3.0.0", @@ -1960,64 +2449,6 @@ "sliced": "1.0.1" }, "dependencies": { - "bluebird": { - "version": "3.5.0", - "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.0.tgz", - "integrity": "sha1-eRQg1/VR7qKJdFOop3ZT+WYG1nw=" - }, - "debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "requires": { - "ms": "2.0.0" - } - }, - "kareem": { - "version": "2.0.7", - "resolved": "https://registry.npmjs.org/kareem/-/kareem-2.0.7.tgz", - "integrity": "sha512-p8+lEpsNs4N0fvNOC1/zzDO0wDrD3Pb1G+OwfIG+gKVK3MyY5jeaGYh+9Qx6jb4fEG2b3E6U98vaE9MH7Gilsw==" - }, - "mongodb": { - "version": "3.0.7", - "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.0.7.tgz", - "integrity": "sha512-n/14kMJEoARXz1qhpNPhUocqy+z5130jhqgEIX1Tsl8UVpHrndQ8et+VmgC4yPK/I8Tcgc93JEMQCHTekBUnNA==", - "requires": { - "mongodb-core": "3.0.7" - } - }, - "mongodb-core": { - "version": "3.0.7", - "resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-3.0.7.tgz", - "integrity": "sha512-z6YufO7s40wLiv2ssFshqoLS4+Kf+huhHq6KZ7gDArsKNzXYjAwTMnhEIJ9GQ8fIfBGs5tBLNPfbIDoCKGPmOw==", - "requires": { - "bson": "1.0.4", - "require_optional": "1.0.1" - } - }, - "mpath": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/mpath/-/mpath-0.4.1.tgz", - "integrity": "sha512-NNY/MpBkALb9jJmjpBlIi6GRoLveLUM0pJzgbp9vY9F7IQEb/HREC/nxrixechcQwd1NevOhJnWWV8QQQRE+OA==" - }, - "mquery": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/mquery/-/mquery-3.0.0.tgz", - "integrity": "sha512-WL1Lk8v4l8VFSSwN3yCzY9TXw+fKVYKn6f+w86TRzOLSE8k1yTgGaLBPUByJQi8VcLbOdnUneFV/y3Kv874pnQ==", - "requires": { - "bluebird": "3.5.0", - "debug": "2.6.9", - "regexp-clone": "0.0.1", - "sliced": "0.0.5" - }, - "dependencies": { - "sliced": { - "version": "0.0.5", - "resolved": "https://registry.npmjs.org/sliced/-/sliced-0.0.5.tgz", - "integrity": "sha1-XtwETKTrb3gW1Qui/GPiXY/kcH8=" - } - } - }, "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", @@ -2052,10 +2483,52 @@ } } }, + "mpath": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/mpath/-/mpath-0.4.1.tgz", + "integrity": "sha512-NNY/MpBkALb9jJmjpBlIi6GRoLveLUM0pJzgbp9vY9F7IQEb/HREC/nxrixechcQwd1NevOhJnWWV8QQQRE+OA==" + }, + "mquery": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/mquery/-/mquery-3.0.0.tgz", + "integrity": "sha512-WL1Lk8v4l8VFSSwN3yCzY9TXw+fKVYKn6f+w86TRzOLSE8k1yTgGaLBPUByJQi8VcLbOdnUneFV/y3Kv874pnQ==", + "requires": { + "bluebird": "3.5.0", + "debug": "2.6.9", + "regexp-clone": "0.0.1", + "sliced": "0.0.5" + }, + "dependencies": { + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "requires": { + "ms": "2.0.0" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + }, + "sliced": { + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/sliced/-/sliced-0.0.5.tgz", + "integrity": "sha1-XtwETKTrb3gW1Qui/GPiXY/kcH8=" + } + } + }, "ms": { "version": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" }, + "nan": { + "version": "2.10.0", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.10.0.tgz", + "integrity": "sha512-bAdJv7fBLhWC+/Bls0Oza+mvTaNQtP+1RyhhhvD95pgUJz6XM5IzgmxOkItJ9tkoCiplvAnXI1tNmmUD/eScyA==", + "optional": true + }, "nanomatch": { "version": "1.2.9", "resolved": "https://registry.npmjs.org/nanomatch/-/nanomatch-1.2.9.tgz", @@ -2168,6 +2641,7 @@ "anymatch": "2.0.0", "async-each": "1.0.1", "braces": "2.3.2", + "fsevents": "1.2.4", "glob-parent": "3.1.0", "inherits": "2.0.3", "is-binary-path": "1.0.1", diff --git a/stackle_api/package.json b/stackle_api/package.json index 9b3c303..06679e5 100644 --- a/stackle_api/package.json +++ b/stackle_api/package.json @@ -35,7 +35,7 @@ "express-jwt": "^5.3.1", "jwks-rsa": "^1.2.1", "method-override": "^2.3.10", - "mongoose": "^5.0.17", + "mongoose": "^5.1.5", "morgan": "^1.9.0", "nodemon": "^1.17.3" }, diff --git a/stackle_api/server.js b/stackle_api/server.js index 5dd4d83..46e08cd 100644 --- a/stackle_api/server.js +++ b/stackle_api/server.js @@ -20,7 +20,6 @@ app.use(bodyParser.json({ type: 'application/vnd.api+json' })); // parse applica app.use(methodOverride()); app.use(cors()); - //serving static index.html file using middleware app.use('/', express.static(__dirname + '/')); @@ -43,11 +42,10 @@ routes(app, db); res.status(500).send('Something broke!') });*/ +// Add option { useMongoClient: true } if mongoose version < 5 +var option = database.option(mongoose.version); - -const options = { useMongoClient: true }; - -mongoose.connect(database.url, options, function (err) { +mongoose.connect(database.url, option, function (err) { console.log("Connecting to the database..."); if (err) { console.log("\nCouldn't connect to local database. Please make sure your local mongodb server is running. \nFind more: https://github.com/scorelab/Stackle#installing-mongodb\n\nConnecting to alternative remote (mongolab) database ...");