Skip to content

Revert "fix lint errors" #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .eslintignore

This file was deleted.

15 changes: 0 additions & 15 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,6 @@
"mocha": true
},
"rules": {
"no-param-reassign": 0,
"global-require": 0,
"func-names": 0,
"no-mixed-operators": 0,
"consistent-return": 0,
"no-unused-expressions": 0,
"newline-per-chained-call": 0,
"no-underscore-dangle": 0,
"import/no-extraneous-dependencies": ["error", {"devDependencies": true, "optionalDependencies": false, "peerDependencies": false}],
"max-len": ["error", {
"code": 120,
"ignoreComments": true,
"ignoreTrailingComments": true,
"tabWidth": 2
}],
"valid-jsdoc": ["error", {
"requireReturn": true,
"requireReturnType": true,
Expand Down
56 changes: 28 additions & 28 deletions config/sample.local.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
// force using test.json for unit tests

let config;
var config
if (process.env.NODE_ENV === 'test') {
config = require('./test.json');
config = require('./test.json')
} else {
config = {
authSecret: 'secret',
logLevel: 'debug',
captureLogs: 'false',
logentriesToken: '',
rabbitmqURL: 'amqp://dockerhost:5672',
fileServiceEndpoint: 'https://api.topcoder-dev.com/v3/files/',
topicServiceEndpoint: 'https://api.topcoder-dev.com/v4/topics/',
directProjectServiceEndpoint: 'https://api.topcoder-dev.com/v3/direct',
userServiceUrl: 'https://api.topcoder-dev.com/v3/users',
connectProjectsUrl: 'https://connect.topcoder-dev.com/projects/',
salesforceLead: {
webToLeadUrl: 'https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8',
orgId: '00D2C0000000dO6',
projectNameFieldId: 'title',
projectDescFieldId: 'description',
projectLinkFieldId: 'URL',
projectIdFieldId: '00N2C000000Vxxx',
},
dbConfig: {
masterUrl: 'postgres://coder:mysecretpassword@dockerhost:5432/projectsdb',
maxPoolSize: 50,
minPoolSize: 4,
idleTimeout: 1000,
},
};
"authSecret": "secret",
"logLevel": "debug",
"captureLogs": "false",
"logentriesToken": "",
"rabbitmqURL": "amqp://dockerhost:5672",
"fileServiceEndpoint": "https://api.topcoder-dev.com/v3/files/",
"topicServiceEndpoint": "https://api.topcoder-dev.com/v4/topics/",
"directProjectServiceEndpoint": "https://api.topcoder-dev.com/v3/direct",
"userServiceUrl": "https://api.topcoder-dev.com/v3/users",
"connectProjectsUrl": "https://connect.topcoder-dev.com/projects/",
"salesforceLead" : {
"webToLeadUrl": 'https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8',
"orgId": "00D2C0000000dO6",
"projectNameFieldId": "title",
"projectDescFieldId": "description",
"projectLinkFieldId": "URL",
"projectIdFieldId" : "00N2C000000Vxxx"
},
"dbConfig": {
"masterUrl": "postgres://coder:mysecretpassword@dockerhost:5432/projectsdb",
"maxPoolSize": 50,
"minPoolSize": 4,
"idleTimeout": 1000
}
}
}
module.exports = config;
module.exports = config
16 changes: 8 additions & 8 deletions migrations/sync.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
'use strict'

/**
* Sync the database models to db tables.
*/

import winston from 'winston';

/**
* Make sure we are in development mode
* @type {String}
*/
// process.env.NODE_ENV = 'development'

require('../dist/models').default.sequelize.sync({ force: true })
require('./dist/models').default.sequelize.sync({ force: true })
.then(() => {
winston.info('Database synced successfully');
process.exit();
console.log('Database synced successfully')
process.exit()
}).catch((err) => {
winston.error('Error syncing database', err);
process.exit(1);
});
console.error('Error syncing database', err)
process.exit(1)
})
16 changes: 8 additions & 8 deletions newrelic.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@

'use strict'

/**
* New Relic agent configuration.
*
* See lib/config.defaults.js in the agent distribution for a more complete
* description of configuration variables and their potential values.
*/
let appName = 'tc-projects-service';
var appName = "tc-projects-service"
if (process.env.NODE_ENV === 'development') {
appName += '-dev';
appName += "-dev"
} else if (process.env.NODE_ENV === 'qa') {
appName += '-qa';
appName += "-qa"
} else {
appName += '-prod';
appName += '-prod'
}

exports.config = {
Expand All @@ -30,6 +30,6 @@ exports.config = {
* issues with the agent, 'info' and higher will impose the least overhead on
* production applications.
*/
level: 'info',
},
};
level: 'info'
}
}
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"scripts": {
"build": "babel src -d dist --presets es2015",
"sync": "node migrations/sync.js",
"lint": "./node_modules/.bin/eslint .",
"lint:fix": "./node_modules/.bin/eslint . --fix || true",
"lint": "./node_modules/.bin/eslint src",
"prestart": "npm run -s build",
"start": "node dist",
"start:dev": "NODE_ENV=local PORT=8001 nodemon -w src --exec \"babel-node src --presets es2015\" | ./node_modules/.bin/bunyan",
Expand Down Expand Up @@ -48,8 +47,7 @@
"pg": "^4.5.5",
"pg-native": "^1.10.0",
"sequelize": "^3.23.0",
"tc-core-library-js": "^1.0.8",
"winston": "^2.3.1"
"tc-core-library-js": "^1.0.8"
},
"devDependencies": {
"babel-cli": "^6.9.0",
Expand Down
4 changes: 3 additions & 1 deletion src/events/projects/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

import config from 'config';
import querystring from 'querystring';
import util from '../../util';

/**
* Creates a lead in salesforce for the connect project.
Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@


import models from './models';

// include newrelic
if (process.env.NODE_ENV !== 'test' && process.env.NODE_ENV !== 'local') {
require('newrelic');
Expand All @@ -9,7 +11,6 @@ const app = require('./app');

/**
* Handle server shutdown gracefully
* @return {Void} This function returns void
*/
function gracefulShutdown() {
app.services.pubsub.disconnect()
Expand Down
3 changes: 1 addition & 2 deletions src/middlewares/checkRole.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
* @version 1.0
*/
import config from 'config';

const util = require('tc-core-library-js').util(config);

module.exports = function (roleName) {
return function (req, res, next) {
if (!req.authUser || !Array.isArray(req.authUser.roles) || req.authUser.roles.indexOf(roleName) === -1) {
if (!req.authUser || !Array.isArray(req.authUser.roles) || req.authUser.roles.indexOf(roleName) == -1) {
return res.status(403)
.json(util.wrapErrorResponse(req.id, 403, 'You are not allowed to perform this action.'));
}
Expand Down
5 changes: 1 addition & 4 deletions src/mocks/addBillingAccount.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* eslint-disable max-len */
import winston from 'winston';

const http = require('https');

const options = {
Expand All @@ -26,7 +23,7 @@ const req = http.request(options, (res) => {

res.on('end', () => {
const body = Buffer.concat(chunks);
winston.info(body.toString());
console.log(body.toString());
});
});
req.write('{\n "billingAccountId": 123456789\n}');
Expand Down
5 changes: 1 addition & 4 deletions src/mocks/addCopilot.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* eslint-disable max-len */
import winston from 'winston';

const http = require('https');

const options = {
Expand All @@ -26,7 +23,7 @@ const req = http.request(options, (res) => {

res.on('end', () => {
const body = Buffer.concat(chunks);
winston.info(body.toString());
console.log(body.toString());
});
});
req.write('{\n "copilotUserId": 123456789\n}');
Expand Down
5 changes: 1 addition & 4 deletions src/mocks/createProject.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* eslint-disable max-len */
import winston from 'winston';

const http = require('https');

const options = {
Expand All @@ -26,7 +23,7 @@ const req = http.request(options, (res) => {

res.on('end', () => {
const body = Buffer.concat(chunks);
winston.info(body.toString());
console.log(body.toString());
});
});

Expand Down
57 changes: 27 additions & 30 deletions src/mocks/direct.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@


import express, { Router } from 'express';
import express from 'express';
import _ from 'lodash';
import bodyParser from 'body-parser';
import config from 'config';
import coreLib from 'tc-core-library-js';
import expressRequestId from 'express-request-id';
import Router from 'express';
import https from 'https';
import path from 'path';
import fs from 'fs';

const util = require('tc-core-library-js').util(config);
const jwtAuth = require('tc-core-library-js').middleware.jwtAuthenticator;

config.version = 'v3';

const util = require('tc-core-library-js').util(config);
const app = express();
app.use(bodyParser.urlencoded({
extended: false,
Expand All @@ -36,9 +33,10 @@ app.use(coreLib.middleware.logger(null, logger));
app.logger = logger;

const router = Router();
const jwtAuth = require('tc-core-library-js').middleware.jwtAuthenticator;
router.all('/v3/direct/projects*', jwtAuth());

const projectId = 2;
let projectId = 2;
const projects = {
1: {
projectName: 'test direct project1',
Expand All @@ -57,56 +55,55 @@ router.route('/v3/direct/projects')
})
.post((req, res) => {
app.logger.info({ body: req.body }, 'create direct project');
const newId = projectId + 1;
const newId = projectId++;
req.body.id = newId;
projects[newId] = req.body;
res.json(util.wrapResponse(req.id, { projectId: newId }));
});

router.route('/v3/direct/projects/:projectId(\\d+)/billingaccount')
.post((req, res) => {
const pId = req.params.projectId;
app.logger.info({ body: req.body, pId }, 'add billingaccount to Project');
if (projects[pId]) {
projects[pId] = _.merge(projects[pId], req.body);
res.json(util.wrapResponse(req.id, { billingAccountName: 'mock account name for ' +
`${req.body.billingAccountId}` }));
const projectId = req.params.projectId;
app.logger.info({ body: req.body, projectId }, 'add billingaccount to Project');
if (projects[projectId]) {
projects[projectId] = _.merge(projects[projectId], req.body);
res.json(util.wrapResponse(req.id, { billingAccountName: `mock account name for ${req.body.billingAccountId}` }));
} else {
res.json(util.wrapErrorResponse(req.id, 404, `Cannot find direct project ${pId}`));
res.json(util.wrapErrorResponse(req.id, 404, `Cannot find direct project ${projectId}`));
}
});


router.route('/v3/direct/projects/:projectId(\\d+)/copilot')
.post((req, res) => {
const pId = req.params.projectId;
app.logger.info({ body: req.body, pId }, 'add copilot to Project');
if (projects[pId]) {
projects[pId] = _.merge(projects[pId], req.body);
res.json(util.wrapResponse(req.id, { copilotProjectId: pId }));
const projectId = req.params.projectId;
app.logger.info({ body: req.body, projectId }, 'add copilot to Project');
if (projects[projectId]) {
projects[projectId] = _.merge(projects[projectId], req.body);
res.json(util.wrapResponse(req.id, { copilotProjectId: projectId }));
} else {
res.json(util.wrapErrorResponse(req.id, 404, `Cannot find direct project ${pId}`));
res.json(util.wrapErrorResponse(req.id, 404, `Cannot find direct project ${projectId}`));
}
})
.delete((req, res) => {
const pId = req.params.projectId;
app.logger.info({ body: req.body, pId }, 'remove copilot from Project');
if (projects[pId]) {
projects[pId] = _.omit(projects[pId], 'copilotUserId');
const projectId = req.params.projectId;
app.logger.info({ body: req.body, projectId }, 'remove copilot from Project');
if (projects[projectId]) {
projects[projectId] = _.omit(projects[projectId], 'copilotUserId');
res.json(util.wrapResponse(req.id, true));
} else {
res.json(util.wrapErrorResponse(req.id, 404, `Cannot find direct project ${pId}`));
res.json(util.wrapErrorResponse(req.id, 404, `Cannot find direct project ${projectId}`));
}
});

router.route('/v3/direct/projects/:projectId(\\d+)/permissions')
.post((req, res) => {
const pId = req.params.projectId;
app.logger.info({ body: req.body, pId }, 'add permissions to Project');
if (projects[pId]) {
const projectId = req.params.projectId;
app.logger.info({ body: req.body, projectId }, 'add permissions to Project');
if (projects[projectId]) {
res.json();
} else {
res.json(util.wrapErrorResponse(req.id, 404, `Cannot find direct project ${pId}`));
res.json(util.wrapErrorResponse(req.id, 404, `Cannot find direct project ${projectId}`));
}
});

Expand Down
Loading