Skip to content

Commit

Permalink
chore: merge pull request #4 from AEGEE/add-healthcheck-endpoint
Browse files Browse the repository at this point in the history
Add /healthcheck endpoint
  • Loading branch information
serge1peshcoff authored Aug 11, 2019
2 parents e8dac78 + 82595c1 commit c7c7574
Show file tree
Hide file tree
Showing 17 changed files with 1,736 additions and 1,345 deletions.
105 changes: 13 additions & 92 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,113 +1,34 @@
# [0.5.0](https://github.com/AEGEE/oms-discounts/compare/0.4.2...0.5.0) (2019-05-18)
## 0.5.1 (2019-08-11)


### Bug Fixes

* **categories:** fixed categories endpoints ([08320a0](https://github.com/AEGEE/oms-discounts/commit/08320a0))


### Features

* **discounts:** added categories. Fixes MEMB-529 ([67d7380](https://github.com/AEGEE/oms-discounts/commit/67d7380))
* **test:** testing categories CRUD ([53af8e7](https://github.com/AEGEE/oms-discounts/commit/53af8e7))



## [0.4.2](https://github.com/AEGEE/oms-discounts/compare/0.4.1...0.4.2) (2019-05-03)


### Bug Fixes

* **codes:** fix claimed date ([a060bdf](https://github.com/AEGEE/oms-discounts/commit/a060bdf))



## [0.4.1](https://github.com/AEGEE/oms-discounts/compare/0.4.0...0.4.1) (2019-05-03)


### Bug Fixes

* **codes:** fix mailer template breaking ([589f490](https://github.com/AEGEE/oms-discounts/commit/589f490))



# [0.4.0](https://github.com/AEGEE/oms-discounts/compare/0.3.3...0.4.0) (2019-05-03)


### Features

* **codes:** mailing code to a member on claiming. Fixed MEMB-528 ([147ad23](https://github.com/AEGEE/oms-discounts/commit/147ad23))
* **test:** tests refactor ([3e665ef](https://github.com/AEGEE/oms-discounts/commit/3e665ef))



## [0.3.3](https://github.com/AEGEE/oms-discounts/compare/0.3.2...0.3.3) (2019-04-29)


### Bug Fixes

* **integration:** quota_period now can be only day, month or year ([67ee4bb](https://github.com/AEGEE/oms-discounts/commit/67ee4bb))



## [0.3.2](https://github.com/AEGEE/oms-discounts/compare/0.3.1...0.3.2) (2019-04-29)


### Bug Fixes

* **deps:** downgraded Sequelize to 4.x to avoid camelCase ([a7f898b](https://github.com/AEGEE/oms-discounts/commit/a7f898b))
* **integration:** integration code is unique now ([d2a795c](https://github.com/AEGEE/oms-discounts/commit/d2a795c))



## [0.3.1](https://github.com/AEGEE/oms-discounts/compare/0.3.0...0.3.1) (2019-04-28)


### Features

* **integration:** add single integration displaying ([bb73032](https://github.com/AEGEE/oms-discounts/commit/bb73032))



# [0.3.0](https://github.com/AEGEE/oms-discounts/compare/0.2.0...0.3.0) (2019-04-28)


### Bug Fixes

* **general:** added Codecov package ([fad3cfe](https://github.com/AEGEE/oms-discounts/commit/fad3cfe))
* **general:** updated Bugsnag key ([e2d8ccc](https://github.com/AEGEE/oms-discounts/commit/e2d8ccc))
* **integration:** integration code is unique now ([d2a795c](https://github.com/AEGEE/oms-discounts/commit/d2a795c))
* **integration:** quota_period now can be only day, month or year ([67ee4bb](https://github.com/AEGEE/oms-discounts/commit/67ee4bb))
* **other:** added /healthcheck endpoint. Fixes MEMB-582 ([396a646](https://github.com/AEGEE/oms-discounts/commit/396a646))


### Features

* **code:** add code model ([a7dd4e2](https://github.com/AEGEE/oms-discounts/commit/a7dd4e2))
* **code:** added code middlewares ([508a460](https://github.com/AEGEE/oms-discounts/commit/508a460))
* **codes:** mailing code to a member on claiming. Fixed MEMB-528 ([147ad23](https://github.com/AEGEE/oms-discounts/commit/147ad23))
* **discounts:** added categories. Fixes MEMB-529 ([67d7380](https://github.com/AEGEE/oms-discounts/commit/67d7380))
* **general:** discounts + eslint ([31a75f5](https://github.com/AEGEE/oms-discounts/commit/31a75f5))
* **general:** integrations management (not tested yet) ([4e168a2](https://github.com/AEGEE/oms-discounts/commit/4e168a2))
* **integration:** add single integration displaying ([bb73032](https://github.com/AEGEE/oms-discounts/commit/bb73032))
* **test:** add basic test infrastructure ([80a6a3f](https://github.com/AEGEE/oms-discounts/commit/80a6a3f))
* **test:** added tests for everything ([a1e77d5](https://github.com/AEGEE/oms-discounts/commit/a1e77d5))
* **test:** testing categories CRUD ([53af8e7](https://github.com/AEGEE/oms-discounts/commit/53af8e7))
* **test:** testing codes claiming and displaying ([bb3b649](https://github.com/AEGEE/oms-discounts/commit/bb3b649))



# [0.2.0](https://github.com/AEGEE/oms-discounts/compare/v0.1.0...0.2.0) (2019-04-28)


### Features

* **test:** add basic test infrastructure ([80a6a3f](https://github.com/AEGEE/oms-discounts/commit/80a6a3f))
* **test:** tests refactor ([3e665ef](https://github.com/AEGEE/oms-discounts/commit/3e665ef))
* **test:** travis integration ([5acac0a](https://github.com/AEGEE/oms-discounts/commit/5acac0a))



# [0.1.0](https://github.com/AEGEE/oms-discounts/compare/e2d8ccc...v0.1.0) (2019-04-27)


### Bug Fixes

* **general:** updated Bugsnag key ([e2d8ccc](https://github.com/AEGEE/oms-discounts/commit/e2d8ccc))


### Features

* **general:** discounts + eslint ([31a75f5](https://github.com/AEGEE/oms-discounts/commit/31a75f5))
* **general:** integrations management (not tested yet) ([4e168a2](https://github.com/AEGEE/oms-discounts/commit/4e168a2))



2 changes: 1 addition & 1 deletion lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ MyAEGEE discounts team.`;

// A helper to determine if user has permission.
function hasPermission(permissionsList, combinedPermission) {
return permissionsList.some(permission => permission.combined.endsWith(combinedPermission));
return permissionsList.some((permission) => permission.combined.endsWith(combinedPermission));
}

exports.getPermissions = (user, corePermissions) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/integrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ exports.addCodesToIntegration = async (req, res) => {
return errors.makeBadRequestError(res, 'No codes are provided.');
}

const arrayToCreate = req.body.map(code => ({
const arrayToCreate = req.body.map((code) => ({
integration_id: req.integration.id,
value: code
}));
Expand Down
2 changes: 1 addition & 1 deletion lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const logger = winston.createLogger({
winston.format.timestamp(),
winston.format.align(),
winston.format.splat(),
winston.format.printf(info => `${info.timestamp} [${info.level}]: ${info.message}`),
winston.format.printf((info) => `${info.timestamp} [${info.level}]: ${info.message}`),
)
})
]
Expand Down
13 changes: 13 additions & 0 deletions lib/middlewares.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const errors = require('./errors');
const helpers = require('./helpers');
const logger = require('./logger');
const bugsnag = require('./bugsnag');
const packageInfo = require('../package');

exports.authenticateUser = async (req, res, next) => {
const token = req.header('x-auth-token');
Expand Down Expand Up @@ -42,6 +43,18 @@ exports.authenticateUser = async (req, res, next) => {
return next();
};

/* istanbul ignore next */
exports.healthcheck = (req, res) => {
return res.json({
success: true,
data: {
name: packageInfo.name,
description: packageInfo.description,
version: packageInfo.version
}
});
};

/* eslint-disable no-unused-vars */
exports.notFound = (req, res, next) => errors.makeNotFoundError(res, 'No such API endpoint: ' + req.method + ' ' + req.originalUrl);

Expand Down
4 changes: 2 additions & 2 deletions lib/sequelize.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ for (const field of requiredFields) {
}
}

Sequelize.postgres.DECIMAL.parse = value => parseFloat(value);
Sequelize.postgres.DECIMAL.parse = (value) => parseFloat(value);

const getSequelize = () => new Sequelize(config.postgres.database, config.postgres.username, config.postgres.password, {
host: config.postgres.host,
port: config.postgres.port,
dialect: 'postgres',
logging: sql => logger.debug(sql),
logging: (sql) => logger.debug(sql),
operatorsAliases: false
});

Expand Down
3 changes: 2 additions & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ process.on('unhandledRejection', (err) => {
}
});

GeneralRouter.get('/healthcheck', middlewares.healthcheck);
GeneralRouter.use(middlewares.authenticateUser);

// integrations and codes
Expand Down Expand Up @@ -60,7 +61,7 @@ async function startServer() {
return res();
});
/* istanbul ignore next */
localApp.on('error', err => rej(new Error('Error starting server: ' + err.stack)));
localApp.on('error', (err) => rej(new Error('Error starting server: ' + err.stack)));
});
}

Expand Down
2 changes: 1 addition & 1 deletion migrations/20190427100249-create-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ module.exports = {
type: Sequelize.DATE
}
}),
down: queryInterface => queryInterface.dropTable('integrations')
down: (queryInterface) => queryInterface.dropTable('integrations')
};
2 changes: 1 addition & 1 deletion migrations/20190428134103-create-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ module.exports = {
type: Sequelize.DATE
}
}),
down: queryInterface => queryInterface.dropTable('codes')
down: (queryInterface) => queryInterface.dropTable('codes')
};
2 changes: 1 addition & 1 deletion migrations/20190518200032-create-category.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ module.exports = {
type: Sequelize.DATE
}
}),
down: queryInterface => queryInterface.dropTable('categories')
down: (queryInterface) => queryInterface.dropTable('categories')
};
7 changes: 6 additions & 1 deletion models/Category.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ const Category = sequelize.define('category', {
}
},
}
}, { underscored: true, tableName: 'categories' });
}, {
underscored: true,
tableName: 'categories',
createdAt: 'created_at',
updatedAt: 'updated_at'
});

module.exports = Category;
7 changes: 6 additions & 1 deletion models/Code.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ const Code = sequelize.define('code', {
claimed_by: {
type: Sequelize.INTEGER
}
}, { underscored: true, tableName: 'codes' });
}, {
underscored: true,
tableName: 'codes',
createdAt: 'created_at',
updatedAt: 'updated_at'
});

module.exports = Code;
7 changes: 6 additions & 1 deletion models/Integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ const Integration = sequelize.define('integration', {
description: {
type: Sequelize.TEXT
}
}, { underscored: true, tableName: 'integrations' });
}, {
underscored: true,
tableName: 'integrations',
createdAt: 'created_at',
updatedAt: 'updated_at'
});

module.exports = Integration;
4 changes: 2 additions & 2 deletions models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const Integration = require('./Integration');
const Code = require('./Code');
const Category = require('./Category');

Integration.hasMany(Code);
Code.belongsTo(Integration);
Integration.hasMany(Code, { foreignKey: 'integration_id' });
Code.belongsTo(Integration, { foreignKey: 'integration_id' });

module.exports = {
Integration,
Expand Down
Loading

0 comments on commit c7c7574

Please sign in to comment.