aviation-model
Version:
Public methods for querying the information from aviation-pg
170 lines (131 loc) • 3.7 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: src/index.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: src/index.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>"use strict";
var Sequelize = require("sequelize");
/**
* Details for the connection
* @type {Sequelize}
*/
var sequelize = new Sequelize("aviation", "aviator", null, {
host: "localhost",
dialect: "postgres",
port: 5432,
pool: {
max: 5,
min: 0,
idle: 1 + 1000
},
logging: false
});
/**
* Importing modules.
*/
var Airport = sequelize.import("../modules/airport.js");
/**
* Airport Methods.
*/
function getAirportByIcao(icao, callback) {
Airport.findOne({
where: {
icao: icao
}
}).then(function (airport) {
// console.log(airport.getName);
callback(airport.dataValues);
});
}
function getAirportName(value, type, callback) {
Airport.findOne({
where: {
[type]: value
}
}).then(function (data) {
callback(data.getName);
});
}
function getAirportCoordinates(value, type, callback) {
Airport.findOne({
where: {
[type]: value
}
}).then(function (data) {
callback(data.getLocation);
});
}
// bermi: previous methods refactored into this one so we can use it for all
// the methods we want.
/**
* Retrieves the data information from the database.
* @param {Object} options
* @param {String} options.type [ icao | iata | name | nickname ]
* @param {String} options.value the value according to the type specified.
* @param {String} options.method [ Name | Location | Latitude | Longitude ]
*
* @param {Function} callback
* @return {string} requested information.
*
* @example
* ```javascript
* getAirportData({
* value: "ALC",
* type: "iata",
* method: "Latitude"
* }, function (data) {
* console.log(data);
* }
* ```
*/
function getAirportData(options, callback) {
var logging = options.verbose || false;
if (options.verbose === true) {
logging = console.log;//eslint-disable-line no-console
}
sequelize.sync({ logging: logging });
Airport.findOne({
where: {
[options.type]: options.value
}
}).then(function (data) {
callback(data["get" + options.method]);
});
}
/**
* Exporting methods.
*/
module.exports = {
getAirportByIcao: getAirportByIcao,
getAirportName: getAirportName,
getAirportCoordinates: getAirportCoordinates,
getAirportData: getAirportData
};
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#Airport">Airport</a></li><li><a href="global.html#getAirportByIcao">getAirportByIcao</a></li><li><a href="global.html#getAirportData">getAirportData</a></li><li><a href="global.html#getterMethods">getterMethods</a></li><li><a href="global.html#sequelize">sequelize</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Wed Apr 27 2016 17:06:28 GMT+0200 (CEST)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>