Brandon Nicholls
Committed by GitHub

Merge pull request #716 from iambrandonn/RESCOI-873

RESCOI-873: Enhanced Logging
Showing 60 changed files with 714 additions and 410 deletions
......@@ -135,6 +135,23 @@ System configuration for COI is done with environment variables. Environment var
>: the log level to use. 0 (Info), 1 (Warn), 2 (Error)
>*Default*: 2
>
>**DEBUG**:
The components to generate logs for. Uses the [debug](https://www.npmjs.com/package/debug) package. `coi` is the app namespace, each module (i.e. a `.js` file) has a sub namespace, and db modules only have a namespace for each function.
>
*Note: Error level logs will always be displayed independent of this variable.*
>
*Examples*:
>
`coi:*` - Display all logs generated for the given LOG_LEVEL
>
`coi:ProjectDB:*` - Only display logs generated in the project-db.js module
>
`coi:ProjectDB:insertProject` - Only display logs generated by the insertProject function in the project-db.js module
>
`coi:ProjectDB:insertProject,coi:DisclosureDB:*` - Only display logs from the disclosure-db.js module or the insertProject function
>
*Default:* `coi:*`
>
>**TRUST_PROXY**
>: The value to pass to app.set('trust_proxy', <YOUR STRING HERE>)
>*Default*: *None*
......
......@@ -128,8 +128,7 @@ module.exports = {
}),
query.select('status_cd as statusCd', 'description').from('disclosure_status'),
query.select('type_cd as typeCd', 'description').from('project_type')
])
.then(function (result) {
]).then(function (result) {
var config = {};
config.matrixTypes = result[0];
config.matrixTypes.map(function (type) {
......
This diff is collapsed. Click to expand it.
......@@ -19,15 +19,16 @@
/* eslint-disable prefer-arrow-callback */
exports.up = function(knex) {
return knex.schema.table('config', function(table) {
table.string('user_id', 40);
})
.table('config', function(table) {
table.string('user_name', 100);
})
.table('config', function(table) {
table.dateTime('updated_date', true);
});
return knex.schema
.table('config', function(table) {
table.string('user_id', 40);
})
.table('config', function(table) {
table.string('user_name', 100);
})
.table('config', function(table) {
table.dateTime('updated_date', true);
});
};
exports.down = function() {
......
......@@ -19,12 +19,13 @@
/* eslint-disable prefer-arrow-callback */
exports.up = function(knex) {
return knex.schema.table('additional_reviewer', function(table) {
table.boolean('active').notNullable().defaultTo(true);
})
.table('additional_reviewer', function(table) {
table.text('dates'); //-- json collection of dates
});
return knex.schema
.table('additional_reviewer', function(table) {
table.boolean('active').notNullable().defaultTo(true);
})
.table('additional_reviewer', function(table) {
table.text('dates'); //-- json collection of dates
});
};
exports.down = function() {
......
......@@ -31,13 +31,13 @@ exports.up = function(knex) {
return knex('disclosure_status')
.update({description: 'Revision Required'})
.where({status_cd: 4})
.then(function() {
return knex('disclosure_status')
.insert({
status_cd: 7,
description: 'Update Needed'
.then(function() {
return knex('disclosure_status')
.insert({
status_cd: 7,
description: 'Update Needed'
});
});
});
};
exports.down = function() {
......
......@@ -19,22 +19,23 @@
/* eslint-disable prefer-arrow-callback, camelcase */
exports.up = function(knex) {
return knex.schema.table('notification_template', function(table) {
table.integer('value');
})
.table('notification_template', function(table) {
table.text('period');
})
.then(function() {
return knex('notification_template')
.insert({
template_id: 9,
type: 'Reporter Notifications',
description: 'Notify reporter when their expiration is about to expire.',
value: 30,
period: 'days'
});
});
return knex.schema
.table('notification_template', function(table) {
table.integer('value');
})
.table('notification_template', function(table) {
table.text('period');
})
.then(function() {
return knex('notification_template')
.insert({
template_id: 9,
type: 'Reporter Notifications',
description: 'Notify reporter when their expiration is about to expire.',
value: 30,
period: 'days'
});
});
};
exports.down = function() {
......
......@@ -19,23 +19,24 @@
/* eslint-disable prefer-arrow-callback, camelcase */
exports.up = function(knex) {
return knex.schema.table('disclosure', function(table) {
table.dropForeign('disposition_type_cd');
})
.table('disclosure', function(table) {
table.dropColumn('disposition_type_cd');
})
.dropTableIfExists('disposition_type')
.createTable('disposition_type', function(table) {
table.increments('type_cd').notNullable().primary();
table.string('description', 50).notNullable();
table.integer('order').notNullable();
table.boolean('active').notNullable();
table.engine('InnoDB');
}).
table('declaration', function(table) {
table.integer('disposition_type_cd').unsigned().references('type_cd').inTable('disposition_type');
});
return knex.schema
.table('disclosure', function(table) {
table.dropForeign('disposition_type_cd');
})
.table('disclosure', function(table) {
table.dropColumn('disposition_type_cd');
})
.dropTableIfExists('disposition_type')
.createTable('disposition_type', function(table) {
table.increments('type_cd').notNullable().primary();
table.string('description', 50).notNullable();
table.integer('order').notNullable();
table.boolean('active').notNullable();
table.engine('InnoDB');
})
.table('declaration', function(table) {
table.integer('disposition_type_cd').unsigned().references('type_cd').inTable('disposition_type');
});
};
exports.down = function() {
......
......@@ -31,12 +31,13 @@ exports.up = function(knex) {
var i = 0;
function updateRow() {
if (i < existingRows.length) {
knex('disposition_type').where('type_cd', existingRows[i].type_cd)
.update({description_copy: existingRows[i].description})
.then(function() {
i++;
updateRow();
}
knex('disposition_type')
.where('type_cd', existingRows[i].type_cd)
.update({description_copy: existingRows[i].description})
.then(function() {
i++;
updateRow();
}
);
} else {
resolve();
......
......@@ -20,10 +20,10 @@
exports.up = function(knex) {
return knex('disclosure_status')
.insert({
status_cd: 8,
description: 'Returned'
});
.insert({
status_cd: 8,
description: 'Returned'
});
};
exports.down = function() {
......
......@@ -29,7 +29,7 @@ export class Test extends LoadTest {
this.CONCURRENT_REQUESTS = 10;
this.method = 'POST';
this.postData = new Buffer(`\r\n------WebKitFormBoundaryTf0LsICBksypVtu7\r\nContent-Disposition: form-data; name="entity"\r\n\r\n{"active":1,"answers":[{"questionId":7,"answer":{"value":"No"}},{"questionId":6,"answer":{"value":["County Government"]}},{"questionId":8,"answer":{"value":"No"}},{"questionId":9,"answer":{"value":"d"}}],"name":"fsdfs","relationships":[{"personCd":1,"relationshipCd":1,"typeCd":1,"amountCd":1,"comments":"d","travel":{},"id":"TMP1448660628733","amount":"$1 - $5,000","type":"Stock","relationship":"Ownership","person":"Self"}]}\r\n------WebKitFormBoundaryTf0LsICBksypVtu7--`); // eslint-disable-line max-len
this.postData = new Buffer('\r\n------WebKitFormBoundaryTf0LsICBksypVtu7\r\nContent-Disposition: form-data; name="entity"\r\n\r\n{"active":1,"answers":[{"questionId":7,"answer":{"value":"No"}},{"questionId":6,"answer":{"value":["County Government"]}},{"questionId":8,"answer":{"value":"No"}},{"questionId":9,"answer":{"value":"d"}}],"name":"fsdfs","relationships":[{"personCd":1,"relationshipCd":1,"typeCd":1,"amountCd":1,"comments":"d","travel":{},"id":"TMP1448660628733","amount":"$1 - $5,000","type":"Stock","relationship":"Ownership","person":"Self"}]}\r\n------WebKitFormBoundaryTf0LsICBksypVtu7--'); // eslint-disable-line max-len
this.id = 0;
this.alreadyAccessed = true;
......
......@@ -49,6 +49,7 @@
"classnames": "2.2.5",
"cookie-parser": "1.4.3",
"cookies-js": "1.2.2",
"debug": "2.3.3",
"draft-js": "0.9.1",
"express": "4.14.0",
"knex": "0.12.5",
......@@ -81,12 +82,12 @@
"css-loader": "0.25.0",
"css-modules-require-hook": "4.0.5",
"enzyme": "2.4.1",
"eslint": "3.7.1",
"eslint": "3.11.1",
"eslint-plugin-contains": "0.0.1",
"eslint-plugin-custom": "file:eslint-plugin-custom",
"eslint-plugin-import": "2.0.1",
"eslint-plugin-import": "2.2.0",
"eslint-plugin-module-name": "0.0.5",
"eslint-plugin-react": "6.4.1",
"eslint-plugin-react": "6.8.0",
"file": "0.2.2",
"jsdom": "9.6.0",
"mocha": "3.1.2",
......@@ -104,8 +105,8 @@
"sinon": "1.17.6",
"skin-deep": "0.16.0",
"style-loader": "0.13.1",
"stylelint": "7.4.2",
"stylelint-config-standard": "13.0.2",
"stylelint": "7.6.0",
"stylelint-config-standard": "15.0.0",
"supertest": "2.0.0",
"trace-line": "0.0.6",
"webpack": "1.13.2"
......
......@@ -34,7 +34,6 @@ import authentication from './middleware/authentication';
import apiAuthentication from './middleware/api-authentication';
import renderView from './middleware/render-view';
import {noCache} from './middleware/cache';
import Log from './log';
import methodChecker from './middleware/method-checker';
import ErrorLogger from './middleware/error-logger';
import { LOG_LEVEL } from '../coi-constants';
......@@ -45,23 +44,27 @@ import scheduleExpirationCheck from './expiration-check';
import impersonationLogger from './middleware/impersonation-logger';
import flags from '../feature-flags.json'; // eslint-disable-line
import initFeatureFlags from './feature-flags';
import {createLogger} from './log';
const log = createLogger('App');
const DEFAULT_PORT = 8090;
initFeatureFlags(flags);
function conditionallyLogRequests(app, logLevel) {
log.logArguments('conditionallyLogRequests', {logLevel});
if (logLevel <= LOG_LEVEL.INFO) {
app.use((req, res, next) => {
const startTime = new Date().getTime();
Log.info('request received', req);
log.info('request received', req);
res.on('finish', () => {
const elapsedTime = new Date().getTime() - startTime;
Log.info(`request finished - ${elapsedTime}ms`, req);
log.info(`request finished - ${elapsedTime}ms`, req);
});
res.on('close', () => {
const elapsedTime = new Date().getTime() - startTime;
Log.info(`request closed - ${elapsedTime}ms`, req);
log.info(`request closed - ${elapsedTime}ms`, req);
});
next();
});
......@@ -71,7 +74,7 @@ function conditionallyLogRequests(app, logLevel) {
function configureProxy(app) {
const TRUST_PROXY = process.env.TRUST_PROXY;
if (TRUST_PROXY) {
Log.info(`Using TRUST_PROXY value of ${TRUST_PROXY}`);
log.info(`Using TRUST_PROXY value of ${TRUST_PROXY}`);
if (TRUST_PROXY.toLowerCase() === 'true') {
app.set('trust proxy', true);
......@@ -106,11 +109,11 @@ export function run() {
logLevel = config.logLevel;
} catch (e) {
if (e.code !== 'MODULE_NOT_FOUND') {
Log.error(e);
log.error(e);
}
else {
logLevel = process.env.LOG_LEVEL;
Log.info('extensions not found');
log.info('extensions not found');
}
}
......
......@@ -18,9 +18,22 @@
/* eslint-disable no-var, prefer-arrow-callback, prefer-template, no-console */
var _ = require('lodash');
function defaultAppLoggers() {
if (_.isEmpty(process.env.DEBUG)) {
process.env.DEBUG = 'coi:*';
var debug = require('debug');
debug.enable(process.env.DEBUG);
}
}
defaultAppLoggers();
require('babel-polyfill');
var app = require('./app');
var Log = require('./log').default;
var createLogger = require('./log').createLogger;
const log = createLogger('Bootstrap');
var application = app.run();
var portNumber = application.get('portNumber');
......@@ -29,11 +42,11 @@ var server = application.listen(portNumber);
console.log('Listening on port ' + portNumber + ' in ' + application.get('env') + ' mode');
process.on('uncaughtException', function(err) {
Log.error('Uncaught exception: ' + err);
Log.error(err);
Log.error('waiting for pending connections to clear');
log.error('Uncaught exception: ' + err);
log.error(err);
log.error('waiting for pending connections to clear');
server.close(function() {
Log.error('shutting down');
log.error('shutting down');
process.exit(1);
});
});
\ No newline at end of file
......
......@@ -16,15 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
import {
createAdditionalReviewer,
unassignAdditionalReviewer,
updateAdditionalReviewer,
getReviewerForDisclosureAndUser,
getDisclosuresForReviewer,
saveRecommendation,
saveProjectRecommendation
} from '../db/additional-reviewer-db';
import ReviewerDB from '../db/additional-reviewer-db';
import { getReviewers } from '../services/auth-service/auth-service';
import { ROLES, DATE_TYPE } from '../../coi-constants';
const { ADMIN, REVIEWER } = ROLES;
......@@ -48,7 +40,7 @@ export const init = app => {
const {knex, body, userInfo, hostname, dbInfo} = req;
let result;
await knex.transaction(async (knexTrx) => {
result = await createAdditionalReviewer(
result = await ReviewerDB.createAdditionalReviewer(
knexTrx,
body,
userInfo.displayName
......@@ -82,7 +74,10 @@ export const init = app => {
);
await knex.transaction(async (knexTrx) => {
await unassignAdditionalReviewer(knexTrx, params.id);
await ReviewerDB.unassignAdditionalReviewer(
knexTrx,
params.id
);
});
res.sendStatus(OK);
}
......@@ -96,7 +91,11 @@ export const init = app => {
{
const {knex, body, userInfo, hostname, dbInfo, params} = req;
await knex.transaction(async (knexTrx) => {
await updateAdditionalReviewer(knexTrx, params.id, body);
await ReviewerDB.updateAdditionalReviewer(
knexTrx,
params.id,
body
);
});
await createAndSendReviewerAssignedNotification(
......@@ -119,7 +118,7 @@ export const init = app => {
const {knex, userInfo, params, dbInfo, hostname, headers} = req;
let additionalReviewer;
await knex.transaction(async (knexTrx) => {
additionalReviewer = await getReviewerForDisclosureAndUser(
additionalReviewer = await ReviewerDB.getReviewerForDisclosureAndUser( // eslint-disable-line max-len
knexTrx,
userInfo.schoolId,
params.disclosureId
......@@ -130,7 +129,7 @@ export const init = app => {
active: false,
dates
};
await updateAdditionalReviewer(
await ReviewerDB.updateAdditionalReviewer(
knexTrx,
additionalReviewer[0].id,
updates
......@@ -171,7 +170,10 @@ export const init = app => {
useKnex,
wrapAsync(async ({knex, userInfo}, res) =>
{
const results = await getDisclosuresForReviewer(knex, userInfo.schoolId);
const results = await ReviewerDB.getDisclosuresForReviewer(
knex,
userInfo.schoolId
);
res.send(results);
}
));
......@@ -192,7 +194,7 @@ export const init = app => {
);
const existingReviewerIds = (
await getReviewerForDisclosureAndUser(
await ReviewerDB.getReviewerForDisclosureAndUser(
knex,
undefined,
params.disclosureId
......@@ -218,7 +220,7 @@ export const init = app => {
wrapAsync(async ({knex, userInfo, params, body}, res) =>
{
await knex.transaction(async (knexTrx) => {
await saveRecommendation(
await ReviewerDB.saveRecommendation(
knexTrx,
userInfo.schoolId,
params.disclosureId,
......@@ -237,7 +239,7 @@ export const init = app => {
wrapAsync(async ({knex, userInfo, params, body}, res) =>
{
await knex.transaction(async (knexTrx) => {
await saveProjectRecommendation(
await ReviewerDB.saveProjectRecommendation(
knexTrx,
userInfo.schoolId,
params.disclosureId,
......
......@@ -16,15 +16,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
import {
getConfig,
archiveConfig,
setConfig,
getArchivedConfig
} from '../db/config-db';
import {
updateAllProjectPersons
} from '../db/project-db';
import ConfigDB from '../db/config-db';
import ProjectDB from '../db/project-db';
import { ROLES } from '../../coi-constants';
const { ADMIN } = ROLES;
import { allowedRoles } from '../middleware/role-check';
......@@ -38,15 +31,26 @@ export async function saveConfig(req, res) {
let config;
await knex.transaction(async (knexTrx) => {
await setConfig(dbInfo, knexTrx, userInfo.schoolId, body, hostname);
config = await getConfig(dbInfo, knexTrx, hostname);
await ConfigDB.setConfig(
dbInfo,
knexTrx,
userInfo.schoolId,
body,
hostname
);
config = await ConfigDB.getConfig(dbInfo, knexTrx, hostname);
config.general = body.general;
await archiveConfig(knexTrx, userInfo.schoolId, userInfo.username, config);
await ConfigDB.archiveConfig(
knexTrx,
userInfo.schoolId,
userInfo.username,
config
);
});
res.send(config);
await updateAllProjectPersons(knex, req);
await ProjectDB.updateAllProjectPersons(knex, req);
await handleNotifications();
}
......@@ -57,7 +61,7 @@ export const init = app => {
useKnex,
wrapAsync(async ({dbInfo, knex, hostname}, res) =>
{
const result = await getConfig(dbInfo, knex, hostname);
const result = await ConfigDB.getConfig(dbInfo, knex, hostname);
res.send(result);
}
));
......@@ -68,7 +72,7 @@ export const init = app => {
useKnex,
wrapAsync(async ({knex, params}, res) =>
{
const result = await getArchivedConfig(knex, params.id);
const result = await ConfigDB.getArchivedConfig(knex, params.id);
res.send(result);
}
));
......
This diff is collapsed. Click to expand it.
......@@ -21,7 +21,7 @@ const { ADMIN } = ROLES;
import { allowedRoles } from '../middleware/role-check';
import wrapAsync from './wrap-async';
import useKnex from '../middleware/request-knex';
import {getFeatureFlags, setFeatureFlagState} from '../db/features-db';
import FeaturesDB from '../db/features-db';
import {ACCEPTED} from '../../http-status-codes';
export const init = app => {
......@@ -30,7 +30,7 @@ export const init = app => {
allowedRoles(ADMIN),
useKnex,
wrapAsync(async ({knex}, res) => {
const flags = await getFeatureFlags(knex);
const flags = await FeaturesDB.getFeatureFlags(knex);
res.send(flags);
})
);
......@@ -41,7 +41,11 @@ export const init = app => {
useKnex,
wrapAsync(async ({knex, params, body}, res) =>
{
await setFeatureFlagState(knex, params.key, body.active === true);
await FeaturesDB.setFeatureFlagState(
knex,
params.key,
body.active === true
);
res.sendStatus(ACCEPTED);
}
));
......
......@@ -17,16 +17,11 @@
*/
import {getFileStream} from '../services/file-service/file-service';
import {
isDisclosureUsers,
isFinancialEntityUsers,
getDisclosureForFinancialEntity
} from '../db/common-db';
import { getDisclosureIdsForReviewer } from '../db/additional-reviewer-db';
import CommonDB from '../db/common-db';
import ReviewerDB from '../db/additional-reviewer-db';
import { ROLES, FILE_TYPE, LANES } from '../../coi-constants';
import * as FileDb from '../db/file-db';
import FileDb from '../db/file-db';
import multer from 'multer';
import Log from '../log';
import {
FORBIDDEN,
ACCEPTED,
......@@ -36,6 +31,8 @@ import { allowedRoles } from '../middleware/role-check';
import wrapAsync from './wrap-async';
import archiver from 'archiver';
import useKnex from '../middleware/request-knex';
import {createLogger} from '../log';
const log = createLogger('FileController');
let upload = multer({dest: process.env.LOCAL_FILE_DESTINATION || 'uploads/' });
try {
......@@ -47,7 +44,7 @@ try {
}
catch (err) {
if (err.code !== 'MODULE_NOT_FOUND') {
Log.error(err);
log.error(err);
}
}
......@@ -66,7 +63,7 @@ async function userHasPermissionForMultiFileUpload(
) {
if (fileType === FILE_TYPE.FINANCIAL_ENTITY) {
if (userInfo.coiRole === ROLES.USER) {
const permitted = await isFinancialEntityUsers(
const permitted = await CommonDB.isFinancialEntityUsers(
knex,
refId,
userInfo.schoolId
......@@ -77,11 +74,11 @@ async function userHasPermissionForMultiFileUpload(
}
if (userInfo.coiRole === ROLES.REVIEWER) {
const disclosureId = await getDisclosureForFinancialEntity(
const disclosureId = await CommonDB.getDisclosureForFinancialEntity(
knex,
refId
);
const reviewerDisclosures = await getDisclosureIdsForReviewer(
const reviewerDisclosures = await ReviewerDB.getDisclosureIdsForReviewer(
knex,
userInfo.schoolId
);
......@@ -91,7 +88,7 @@ async function userHasPermissionForMultiFileUpload(
}
} else {
if (userInfo.coiRole === ROLES.USER) {
const permitted = await isDisclosureUsers(
const permitted = await CommonDB.isDisclosureUsers(
knex,
refId,
userInfo.schoolId
......@@ -102,7 +99,7 @@ async function userHasPermissionForMultiFileUpload(
}
if (userInfo.coiRole === ROLES.REVIEWER) {
const reviewerDisclosures = await getDisclosureIdsForReviewer(
const reviewerDisclosures = await ReviewerDB.getDisclosureIdsForReviewer(
knex,
userInfo.schoolId
);
......
......@@ -21,10 +21,7 @@ const { ADMIN } = ROLES;
import { allowedRoles } from '../middleware/role-check';
import wrapAsync from './wrap-async';
import useKnex from '../middleware/request-knex';
import {
getLatestNotifications,
notificationTemplateIsForCOI
} from '../db/notifications-db';
import NotificationsDB from '../db/notifications-db';
import {FORBIDDEN, NOT_FOUND} from '../../http-status-codes';
import {
getNotificationReceiptDetail
......@@ -36,7 +33,9 @@ export const init = app => {
allowedRoles(ADMIN),
useKnex,
wrapAsync(async ({knex}, res) => {
const notificationRequests = await getLatestNotifications(knex);
const notificationRequests = await NotificationsDB.getLatestNotifications(
knex
);
res.send(notificationRequests);
})
);
......@@ -57,7 +56,10 @@ export const init = app => {
return;
}
const valid = await notificationTemplateIsForCOI(knex, detail.templateId);
const valid = await NotificationsDB.notificationTemplateIsForCOI(
knex,
detail.templateId
);
if (!valid) {
res.sendStatus(FORBIDDEN);
return;
......
......@@ -16,18 +16,14 @@
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
import * as PIDB from '../db/pi-db';
import * as PIReviewDB from '../db/pi-review-db';
import {
isDisclosureUsers,
isFinancialEntityUsers,
isProjectUsers
} from '../db/common-db';
import PIDB from '../db/pi-db';
import PIReviewDB from '../db/pi-review-db';
import CommonDB from '../db/common-db';
import { ROLES } from '../../coi-constants';
const { ADMIN, REVIEWER } = ROLES;
import { allowedRoles } from '../middleware/role-check';
import { FORBIDDEN, NO_CONTENT, ACCEPTED } from '../../http-status-codes';
import { getDisclosureIdsForReviewer } from '../db/additional-reviewer-db';
import ReviewerDB from '../db/additional-reviewer-db';
import {
createAndSendResubmitNotification
} from '../services/notification-service/notification-service';
......@@ -119,7 +115,7 @@ export const init = app => {
allowedRoles('ANY'),
useKnex,
wrapAsync(async ({knex, params, userInfo, body}, res) => {
const isSubmitter = await isDisclosureUsers(
const isSubmitter = await CommonDB.isDisclosureUsers(
knex,
params.disclosureId,
userInfo.schoolId
......@@ -178,7 +174,7 @@ export const init = app => {
allowedRoles('ANY'),
useKnex,
wrapAsync(async ({knex, params, userInfo, body}, res) => {
const isOwner = await isFinancialEntityUsers(
const isOwner = await CommonDB.isFinancialEntityUsers(
knex,
params.entityId,
userInfo.schoolId
......@@ -238,7 +234,7 @@ export const init = app => {
allowedRoles('ANY'),
useKnex,
wrapAsync(async ({knex, params, userInfo, body}, res) => {
const isOwner = await isFinancialEntityUsers(
const isOwner = await CommonDB.isFinancialEntityUsers(
knex,
params.entityId,
userInfo.schoolId
......@@ -296,7 +292,7 @@ export const init = app => {
allowedRoles('ANY'),
useKnex,
wrapAsync(async ({knex, params, userInfo}, res) => {
const isOwner = await isFinancialEntityUsers(
const isOwner = await CommonDB.isFinancialEntityUsers(
knex,
params.entityId,
userInfo.schoolId
......@@ -354,12 +350,12 @@ export const init = app => {
useKnex,
wrapAsync(async ({knex, params, userInfo, body}, res) => {
const [isEntityOwner, isProjectOwner] = await Promise.all([
isFinancialEntityUsers(
CommonDB.isFinancialEntityUsers(
knex,
params.entityId,
userInfo.schoolId
),
isProjectUsers(
CommonDB.isProjectUsers(
knex,
params.projectId,
userInfo.schoolId
......@@ -419,7 +415,7 @@ export const init = app => {
allowedRoles('ANY'),
useKnex,
wrapAsync(async ({knex, params, userInfo, body}, res) => {
const isSubmitter = await isDisclosureUsers(
const isSubmitter = await CommonDB.isDisclosureUsers(
knex,
params.disclosureId,
userInfo.schoolId
......@@ -478,7 +474,7 @@ export const init = app => {
wrapAsync(async (req, res) => {
const {dbInfo, params, userInfo, hostname, headers, body, knex} = req;
const isSubmitter = isDisclosureUsers(
const isSubmitter = CommonDB.isDisclosureUsers(
knex,
params.disclosureId,
userInfo.schoolId
......@@ -529,7 +525,7 @@ export const init = app => {
useKnex,
wrapAsync(async ({knex, params, userInfo}, res) => {
if (userInfo.coiRole === REVIEWER) {
const reviewerDisclosureIds = await getDisclosureIdsForReviewer(
const reviewerDisclosureIds = await ReviewerDB.getDisclosureIdsForReviewer( // eslint-disable-line max-len
knex,
userInfo.schoolId
);
......@@ -555,7 +551,7 @@ export const init = app => {
allowedRoles('ANY'),
useKnex,
wrapAsync(async ({knex, params, userInfo, body}, res) => {
const isOwner = await isFinancialEntityUsers(
const isOwner = await CommonDB.isFinancialEntityUsers(
knex,
params.entityId,
userInfo.schoolId
......
......@@ -16,13 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
import {
saveProject,
getProjects,
updateProjectPersonDispositionType,
getProjectStatuses,
getProjectStatus
} from '../db/project-db';
import ProjectDB from '../db/project-db';
import { ROLES } from '../../coi-constants';
import { OK, BAD_REQUEST } from '../../http-status-codes';
const { ADMIN } = ROLES;
......@@ -30,8 +24,9 @@ import { allowedRoles } from '../middleware/role-check';
import { filterProjects } from '../services/project-service/project-service';
import wrapAsync from './wrap-async';
import projectIsValid from '../validators/project';
import Log from '../log';
import useKnex from '../middleware/request-knex';
import {createLogger} from '../log';
const log = createLogger('ProjectController');
export const init = app => {
app.post(
......@@ -44,7 +39,7 @@ export const init = app => {
if (!projectIsValid(body)) {
res.status(BAD_REQUEST);
res.json(projectIsValid.errors);
Log.error(
log.error(
`An invalid project was pushed to /api/coi/projects
${JSON.stringify(projectIsValid.errors)}`
);
......@@ -53,7 +48,7 @@ export const init = app => {
let result;
await knex.transaction(async (knexTrx) => {
result = await saveProject(knexTrx, req, body);
result = await ProjectDB.saveProject(knexTrx, req, body);
});
if (!result) {
res.sendStatus(OK);
......@@ -72,7 +67,7 @@ export const init = app => {
useKnex,
wrapAsync(async ({knex, userInfo, query, dbInfo, headers}, res) =>
{
const projects = await getProjects(knex, userInfo.schoolId);
const projects = await ProjectDB.getProjects(knex, userInfo.schoolId);
if (query.filter) {
const result = await filterProjects(
dbInfo,
......@@ -94,7 +89,7 @@ export const init = app => {
wrapAsync(async ({body, params, knex}, res) =>
{
await knex.transaction(async (knexTrx) => {
await updateProjectPersonDispositionType(
await ProjectDB.updateProjectPersonDispositionType(
knexTrx,
body,
parseInt(params.id)
......@@ -110,7 +105,7 @@ export const init = app => {
useKnex,
wrapAsync(async ({dbInfo, knex, params, headers}, res) => {
const {sourceId, projectId} = params;
const result = await getProjectStatuses(
const result = await ProjectDB.getProjectStatuses(
dbInfo,
knex,
sourceId,
......@@ -128,7 +123,7 @@ export const init = app => {
wrapAsync(async ({dbInfo, knex, params, headers}, res) =>
{
const {sourceId, projectId, personId} = params;
const result = await getProjectStatus(
const result = await <