Skip to content

Commit

Permalink
Merge pull request #82 from SayakMukhopadhyay/wip
Browse files Browse the repository at this point in the history
Upgrading to use v4 Elite BGS API
  • Loading branch information
SayakMukhopadhyay authored Jan 8, 2018
2 parents 0456e63 + eadf259 commit 6c8d30b
Show file tree
Hide file tree
Showing 25 changed files with 1,174 additions and 459 deletions.
12 changes: 12 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ const systemsV3 = require('./server/routes/eddb_api/v3/systems');
const ebgsFactionsV3 = require('./server/routes/elite_bgs_api/v3/factions');
const ebgsSystemsV3 = require('./server/routes/elite_bgs_api/v3/systems');

const ebgsFactionsV4 = require('./server/routes/elite_bgs_api/v4/factions');
const ebgsSystemsV4 = require('./server/routes/elite_bgs_api/v4/systems');

const authCheck = require('./server/routes/auth/auth_check');
const authDiscord = require('./server/routes/auth/discord');
const authLogout = require('./server/routes/auth/logout');
Expand Down Expand Up @@ -122,6 +125,11 @@ app.use('/api/ebgs/v3/api-docs.json', (req, res, next) => {
res.send(swagger.EBGSAPIv3);
});

app.use('/api/ebgs/v4/api-docs.json', (req, res, next) => {
res.setHeader('Content-Type', 'application/json');
res.send(swagger.EBGSAPIv4);
});

app.use('/api/eddb/v1/bodies', bodiesV1);
app.use('/api/eddb/v1/commodities', commoditiesV1);
app.use('/api/eddb/v1/factions', factionsV1);
Expand All @@ -147,6 +155,7 @@ app.use('/api/eddb/v3/docs', swaggerUi.serve, swaggerUi.setup(null, null, null,
app.use('/api/ebgs/v1/docs', swaggerUi.serve, swaggerUi.setup(null, null, null, null, null, `http://${host}/api/ebgs/v1/api-docs.json`));
app.use('/api/ebgs/v2/docs', swaggerUi.serve, swaggerUi.setup(null, null, null, null, null, `http://${host}/api/ebgs/v2/api-docs.json`));
app.use('/api/ebgs/v3/docs', swaggerUi.serve, swaggerUi.setup(null, null, null, null, null, `http://${host}/api/ebgs/v3/api-docs.json`));
app.use('/api/ebgs/v4/docs', swaggerUi.serve, swaggerUi.setup(null, null, null, null, null, `http://${host}/api/ebgs/v4/api-docs.json`));

app.use('/api/ebgs/v1/factions', ebgsFactionsV1);
app.use('/api/ebgs/v1/systems', ebgsSystemsV1);
Expand All @@ -171,6 +180,9 @@ app.use('/api/eddb/v3/downloadupdate', downloadUpdateV3);
app.use('/api/ebgs/v3/factions', ebgsFactionsV3);
app.use('/api/ebgs/v3/systems', ebgsSystemsV3);

app.use('/api/ebgs/v4/factions', ebgsFactionsV4);
app.use('/api/ebgs/v4/systems', ebgsSystemsV4);

app.use('/auth/check', authCheck);
app.use('/auth/discord', authDiscord);
app.use('/auth/logout', authLogout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"use strict";

let mongoosePaginate = require('mongoose-paginate');
let mongooseAggregatePaginate = require('mongoose-aggregate-paginate');

module.exports = new Promise((resolve, reject) => {
let db = require('../db');
Expand Down Expand Up @@ -54,9 +53,8 @@ module.exports = new Promise((resolve, reject) => {
}, { runSettersOnQuery: true });

ebgsFaction.plugin(mongoosePaginate);
ebgsFaction.plugin(mongooseAggregatePaginate);

let model = connection.model('ebgsFactionV3o1', ebgsFaction);
let model = connection.model('ebgsFactionV4', ebgsFaction);

resolve(model);
})
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@

"use strict";

let mongoosePaginate = require('mongoose-paginate');
let mongooseAggregatePaginate = require('mongoose-aggregate-paginate');

module.exports = new Promise((resolve, reject) => {
let db = require('../db');
let connection = db.elite_bgs;
Expand All @@ -27,8 +24,8 @@ module.exports = new Promise((resolve, reject) => {
let ObjectId = mongoose.Schema.Types.ObjectId;

let ebgsHistoryFaction = new Schema({
faction_id: ObjectId,
faction_name_lower: String,
faction_id: { type: ObjectId, index: true },
faction_name_lower: { type: String, lowercase: true },
updated_at: { type: Date, index: true },
updated_by: String,
system: String,
Expand All @@ -52,10 +49,7 @@ module.exports = new Promise((resolve, reject) => {
}]
}, { runSettersOnQuery: true });

ebgsHistoryFaction.plugin(mongoosePaginate);
ebgsHistoryFaction.plugin(mongooseAggregatePaginate);

let model = connection.model('ebgsHistoryFactionV3o1', ebgsHistoryFaction);
let model = connection.model('ebgsHistoryFactionV4', ebgsHistoryFaction);

resolve(model);
})
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@

"use strict";

let mongoosePaginate = require('mongoose-paginate');
let mongooseAggregatePaginate = require('mongoose-aggregate-paginate');

module.exports = new Promise((resolve, reject) => {
let db = require('../db');
let connection = db.elite_bgs;
Expand All @@ -27,9 +24,9 @@ module.exports = new Promise((resolve, reject) => {
let ObjectId = mongoose.Schema.Types.ObjectId;

let ebgsHistorySystem = new Schema({
system_id: ObjectId,
system_name_lower: String,
updated_at: Date,
system_id: { type: ObjectId, index: true },
system_name_lower: { type: String, lowercase: true },
updated_at: { type: Date, index: true },
updated_by: String,
population: Number,
government: { type: String, lowercase: true },
Expand All @@ -44,10 +41,7 @@ module.exports = new Promise((resolve, reject) => {
}]
}, { runSettersOnQuery: true });

ebgsHistorySystem.plugin(mongoosePaginate);
ebgsHistorySystem.plugin(mongooseAggregatePaginate);

let model = connection.model('ebgsHistorySystemV3o1', ebgsHistorySystem);
let model = connection.model('ebgsHistorySystemV4', ebgsHistorySystem);

resolve(model);
})
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"use strict";

let mongoosePaginate = require('mongoose-paginate');
let mongooseAggregatePaginate = require('mongoose-aggregate-paginate');

module.exports = new Promise((resolve, reject) => {
let db = require('../db');
Expand Down Expand Up @@ -50,9 +49,8 @@ module.exports = new Promise((resolve, reject) => {
}, { runSettersOnQuery: true });

ebgsSystem.plugin(mongoosePaginate);
ebgsSystem.plugin(mongooseAggregatePaginate);

let model = connection.model('ebgsSystemV3o1', ebgsSystem);
let model = connection.model('ebgsSystemV4', ebgsSystem);

resolve(model);
})
2 changes: 1 addition & 1 deletion server/modules/eddn/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ sock.on('message', topic => {
case journal.schemaId[1]:
// journal.trackSystem(message.message);
journal.trackSystemV3(message.message);
journal.trackSystemV3_1(message.message);
journal.trackSystemV4(message.message);
// journal.display();
break;
// case Outfitting.schemaId:
Expand Down
18 changes: 9 additions & 9 deletions server/modules/eddn/schemas/journal.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ const ebgsFactionsV3Model = require('../../../models/ebgs_factions_v3');
const ebgsSystemsV3Model = require('../../../models/ebgs_systems_v3');
const ebgsStationsV3Model = require('../../../models/ebgs_stations_v3');

const ebgsFactionsV3_1Model = require('../../../models/ebgs_factions_v3.1');
const ebgsSystemsV3_1Model = require('../../../models/ebgs_systems_v3.1');
const ebgsHistoryFactionV3_1Model = require('../../../models/ebgs_history_faction_v3.1');
const ebgsHistorySystemV3_1Model = require('../../../models/ebgs_history_system_v3.1');
const ebgsFactionsV4Model = require('../../../models/ebgs_factions_v4');
const ebgsSystemsV4Model = require('../../../models/ebgs_systems_v4');
const ebgsHistoryFactionV4Model = require('../../../models/ebgs_history_faction_v4');
const ebgsHistorySystemV4Model = require('../../../models/ebgs_history_system_v4');

module.exports = Journal;

Expand Down Expand Up @@ -687,7 +687,7 @@ function Journal() {
}
}

this.trackSystemV3_1 = function (message) {
this.trackSystemV4 = function (message) {
if (message.event === "FSDJump" || message.event === "Location") {
if (message.Factions && this.checkMessage(message)) {
let notNeededFactionIndex = message.Factions.findIndex(faction => {
Expand All @@ -704,7 +704,7 @@ function Journal() {
};
factionArray.push(factionObject);
});
ebgsSystemsV3_1Model
ebgsSystemsV4Model
.then(model => {
model.findOne(
{
Expand Down Expand Up @@ -874,7 +874,7 @@ function Journal() {
.catch(err => {
console.log(err);
});
ebgsFactionsV3_1Model
ebgsFactionsV4Model
.then(model => {
let messageFactionsLower = [];
message.Factions.forEach(faction => {
Expand Down Expand Up @@ -1393,7 +1393,7 @@ function Journal() {

this.setSystemHistory = function (historyObject) {
return new Promise((resolve, reject) => {
ebgsHistorySystemV3_1Model
ebgsHistorySystemV4Model
.then(model => {
let document = new model(historyObject);
document.save()
Expand All @@ -1412,7 +1412,7 @@ function Journal() {

this.setFactionHistory = function (historyObject) {
return new Promise((resolve, reject) => {
ebgsHistoryFactionV3_1Model
ebgsHistoryFactionV4Model
.then(model => {
let document = new model(historyObject);
document.save()
Expand Down
5 changes: 2 additions & 3 deletions server/routes/auth/auth_check.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@ router.get('/edit', (req, res) => {
} else {
let editableFactions = req.user.editable_factions;
let systemName = req.query.name;
require('../../models/ebgs_factions_v3')
require('../../models/ebgs_factions_v4')
.then(model => {
let factionPromise = [];
editableFactions.forEach(faction => {
factionPromise.push(new Promise((resolve, reject) => {
model.findOne(
{ name_lower: faction.name_lower },
{ history: 0 }
{ name_lower: faction.name_lower }
).lean().then(gotFaction => {
if (gotFaction && gotFaction.faction_presence.findIndex(element => {
return element.system_name_lower === systemName.toLowerCase();
Expand Down
10 changes: 4 additions & 6 deletions server/routes/auth/auth_user.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,12 @@ router.post('/edit', (req, res) => {
return element.name_lower === faction.toLowerCase();
}) === -1) {
factionPromise.push(new Promise((resolve, reject) => {
require('../../models/ebgs_factions_v3')
require('../../models/ebgs_factions_v4')
.then(model => {
model.findOne(
{
name_lower: faction.toLowerCase()
},
{ history: 0 }
}
).lean().then(factionGot => {
if (factionGot) {
user.factions.push({
Expand All @@ -74,13 +73,12 @@ router.post('/edit', (req, res) => {
return element.name_lower === system.toLowerCase();
}) === -1) {
systemPromise.push(new Promise((resolve, reject) => {
require('../../models/ebgs_systems_v3')
require('../../models/ebgs_systems_v4')
.then(model => {
model.findOne(
{
name_lower: system.toLowerCase()
},
{ history: 0 }
}
).lean().then(systemGot => {
if (systemGot) {
user.systems.push({
Expand Down
1 change: 1 addition & 0 deletions server/routes/elite_bgs_api/v3/factions.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ let router = express.Router();
* type: array
* items:
* $ref: '#/definitions/EBGSFactionsPageV3'
* deprecated: true
*/
router.get('/', cors(), (req, res, next) => {
require('../../../models/ebgs_factions_v3')
Expand Down
1 change: 1 addition & 0 deletions server/routes/elite_bgs_api/v3/systems.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ let router = express.Router();
* type: array
* items:
* $ref: '#/definitions/EBGSSystemsPageV3'
* deprecated: true
*/
router.get('/', cors(), (req, res, next) => {
require('../../../models/ebgs_systems_v3')
Expand Down
Loading

0 comments on commit 6c8d30b

Please sign in to comment.