<repo_name>abburishiva/es6-node<file_sep>/dist/controller/subject.js
'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _subject = require('../models/subject');

var _subject2 = _interopRequireDefault(_subject);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var SubjectsController = function () {
    function SubjectsController() {
        _classCallCheck(this, SubjectsController);
    }

    _createClass(SubjectsController, [{
        key: 'get',
        value: function get(req, res) {
            _subject2.default.find(function (err, result) {
                res.status(200).json(result);
            });
        }
    }]);

    return SubjectsController;
}();

exports.default = new SubjectsController();<file_sep>/app.js
import express from 'express'
import bodyParser from 'body-parser';
import routes from './routes/index';

class App {
    constructor() {
        this.express = express();
        this.dataCarriers();
        this.mountRoutes();
        this.headers();
    }

    dataCarriers() {
        this.express.use(bodyParser.urlencoded({ extended: false }));
        this.express.use(bodyParser.json());
    }

    headers() {
        this.express.use(function (req, res, next) {
            if (req.url.substr(-1) === '/') {
                return res.send({
                    message: "Welcome To TalentScreen!"
                });
            }
            next();
        });
    }


    mountRoutes() {
        this.express.use('/v1', routes)
    }
}

export default new App().express<file_sep>/routes/index.js
import express from 'express';
const router = express.Router();
import subject from './subject';

router.use('/subjects', subject);

export default router;<file_sep>/routes/subject.js
import express from 'express';
import subJectController from '../controller/subject';
import middlewareAuth from '../utils/auth/middleAuth';
const router = express.Router();

router.get('/', middlewareAuth, subJectController.get);

export default router;<file_sep>/models/subject.js
import connection from '../utils/db/mySqlConnection';

class SubjectModel {

    constructor() {
        this.dbMySQL = connection;
        this.tableOnly = "select s.*,CASE s.flag WHEN 0 THEN 'false' WHEN 1 THEN 'true' END AS flag ,DATE_FORMAT(s.lastmoddatetime,'%b %d %Y %h:%i %p') as lastmoddatetime from  subject s,common_category cc where s.categoryid=cc.id";
        this.deatailTableSQL = "s.id, s.name, s.description ,s.mode ,s.template,s.test_framework ,s.codemirror_theme, s.icon_class,cc.id as common_category__id,cc.name as common_category__name, cc.display_name as common_category__display_name, cc.entityid as common_category__entityid,cc.description as common_category__description,cc.enabled as common_category__enabled";
        this.tableWithDependenciesSQL = this.tableOnly.replace("s.*", this.deatailTableSQL);
    }

    find(callback) {
        this.dbMySQL.query(this.tableOnly, (err, results) => {
            callback(err, results);
        });
    }
}


export default new SubjectModel();<file_sep>/utils/auth/middleAuth.js
import express from 'express';

const middlewareAuth = (req, res, next) => {
    next();
}



export default middlewareAuth;<file_sep>/dist/test/config/mochaConfig.js
'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});

var _mocha = require('mocha');

var _mocha2 = _interopRequireDefault(_mocha);

var _chai = require('chai');

var _chai2 = _interopRequireDefault(_chai);

var _chaiHttp = require('chai-http');

var _chaiHttp2 = _interopRequireDefault(_chaiHttp);

var _app = require('../../app.js');

var _app2 = _interopRequireDefault(_app);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

_chai2.default.use(_chaiHttp2.default);
var expect = _chai2.default.expect;

var MochaConfig = function MochaConfig() {
    _classCallCheck(this, MochaConfig);

    this.chai = _chai2.default;
    this.expect = expect;
    this.app = _app2.default;
};

exports.default = new MochaConfig();<file_sep>/utils/db/mySqlConnection.js
import mysql from 'mysql';
import config from '../../config/config';

const connection = mysql.createPool({
    host: config.dev.mysql.host,
    port: config.dev.mysql.port,
    user: config.dev.mysql.username,
    password: config.dev.mysql.password,
    database: config.dev.mysql.database
});

export default connection;