Add mongoose schemas for logs

pull/15/head
Florian Hartwich 2017-10-21 18:23:04 +02:00
parent 91ebda52b0
commit 443184027e
9 changed files with 272 additions and 16 deletions

39
api/models/logs/budget.js Normal file
View File

@ -0,0 +1,39 @@
"use strict";
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const LogBudgetSchema = new Schema({
war: {
type: mongoose.Schema.Types.ObjectId,
ref: 'War',
required: true
},
time: {
type: Date,
required: true
},
fraction: {
type: String,
enum: ['BLUFOR', 'OPFOR'],
required: true
},
oldBudget: {
type: Number,
get: v => Math.round(v),
set: v => Math.round(v),
required: true
},
newBudget: {
type: Number,
get: v => Math.round(v),
set: v => Math.round(v),
required: true
}
}, {
collection: 'logBudget'
});
// optional more indices
LogBudgetSchema.index({war: 1});
module.exports = mongoose.model('LogBudget', LogBudgetSchema);

35
api/models/logs/flag.js Normal file
View File

@ -0,0 +1,35 @@
"use strict";
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const LogFlagSchema = new Schema({
war: {
type: mongoose.Schema.Types.ObjectId,
ref: 'War',
required: true
},
time: {
type: Date,
required: true
},
player: {
type: String,
required: true
},
flagFraction: {
type: String,
enum: ['BLUFOR', 'OPFOR'],
required: true
},
capture: {
type: Boolean,
required: true
}
}, {
collection: 'logFlag'
});
// optional more indices
LogFlagSchema.index({war: 1, player: 1});
module.exports = mongoose.model('LogFlag', LogFlagSchema);

34
api/models/logs/kill.js Normal file
View File

@ -0,0 +1,34 @@
"use strict";
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const LogKillSchema = new Schema({
war: {
type: mongoose.Schema.Types.ObjectId,
ref: 'War',
required: true
},
time: {
type: Date,
required: true
},
shooter: {
type: String,
required: true
},
target: {
type: String,
required: true
},
friendlyFire: {
type: Boolean,
required: true
}
}, {
collection: 'logKill'
});
// optional more indices
LogKillSchema.index({war: 1, shooter: 1, target: 1});
module.exports = mongoose.model('LogKill', LogKillSchema);

34
api/models/logs/points.js Normal file
View File

@ -0,0 +1,34 @@
"use strict";
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const LogKillSchema = new Schema({
war: {
type: mongoose.Schema.Types.ObjectId,
ref: 'War',
required: true
},
time: {
type: Date,
required: true
},
ptBlufor: {
type: Number,
get: v => Math.round(v),
set: v => Math.round(v),
required: true
},
ptOpfor: {
type: Number,
get: v => Math.round(v),
set: v => Math.round(v),
required: true
}
}, {
collection: 'logKill'
});
// optional more indices
LogKillSchema.index({war: 1, shooter: 1, target: 1});
module.exports = mongoose.model('LogKill', LogKillSchema);

View File

@ -0,0 +1,26 @@
"use strict";
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const LogRespawnSchema = new Schema({
war: {
type: mongoose.Schema.Types.ObjectId,
ref: 'War',
required: true
},
time: {
type: Date,
required: true
},
player: {
type: String,
required: true
}
}, {
collection: 'logRespawn'
});
// optional more indices
LogRespawnSchema.index({war: 1, player: 1});
module.exports = mongoose.model('LogRespawn', LogRespawnSchema);

34
api/models/logs/revive.js Normal file
View File

@ -0,0 +1,34 @@
"use strict";
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const LogReviveSchema = new Schema({
war: {
type: mongoose.Schema.Types.ObjectId,
ref: 'War',
required: true
},
time: {
type: Date,
required: true
},
medic: {
type: String,
required: true
},
patient: {
type: String,
required: true
},
stabilized: {
type: Boolean,
required: true
}
}, {
collection: 'logRevive'
});
// optional more indices
LogReviveSchema.index({war: 1, medic: 1});
module.exports = mongoose.model('LogRevive', LogReviveSchema);

View File

@ -0,0 +1,36 @@
"use strict";
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const LogTransportSchema = new Schema({
war: {
type: mongoose.Schema.Types.ObjectId,
ref: 'War',
required: true
},
time: {
type: Date,
required: true
},
driver: {
type: String,
required: true
},
passenger: {
type: String,
required: true
},
distance: {
type: Number,
get: v => Math.round(v),
set: v => Math.round(v),
required: true
}
}, {
collection: 'logTransport'
});
// optional more indices
LogTransportSchema.index({war: 1});
module.exports = mongoose.model('LogTransport', LogTransportSchema);

View File

@ -23,6 +23,12 @@ const parseWarLog = require('../tools/log-parse-tool');
const CampaignModel = require('../models/campaign'); const CampaignModel = require('../models/campaign');
const WarModel = require('../models/war'); const WarModel = require('../models/war');
const PlayerModel = require('../models/player'); const PlayerModel = require('../models/player');
const LogKillModel = require('../models/logs/kill');
const LogRespawnModel = require('../models/logs/respawn');
const LogReviveModel = require('../models/logs/revive');
const LogTransportModel = require('../models/logs/transport');
const LogFlagModel = require('../models/logs/flag');
const LogBudgetModel = require('../models/logs/budget');
const wars = express.Router(); const wars = express.Router();
@ -81,9 +87,21 @@ wars.route('/')
if (err) { if (err) {
return next(err); return next(err);
} }
LogKillModel.create(statsResult.kills, function (err) {
LogRespawnModel.create(statsResult.respawn, function (err) {
LogReviveModel.create(statsResult.revive, function (err) {
LogFlagModel.create(statsResult.flag, function (err) {
LogBudgetModel.create(statsResult.budget, function (err) {
LogTransportModel.create(statsResult.transport, function (err) {
res.status(codes.created); res.status(codes.created);
res.locals.items = war; res.locals.items = war;
next(); next();
})
})
})
})
})
})
}); });
}) })
}); });

View File

@ -180,7 +180,7 @@ const getRespawnEntry = (respawn, playerName, warId) => {
const getPointsEntry = (pt, warId) => { const getPointsEntry = (pt, warId) => {
return { return {
warId: warId, war: warId,
time: getDateTime(pt[5]), time: getDateTime(pt[5]),
ptBlufor: parseInt(pt[12]), ptBlufor: parseInt(pt[12]),
ptOpfor: parseInt(pt[15].slice(0, -1)) ptOpfor: parseInt(pt[15].slice(0, -1))
@ -189,7 +189,7 @@ const getPointsEntry = (pt, warId) => {
const getBudgetEntry = (budg, warId) => { const getBudgetEntry = (budg, warId) => {
return { return {
warId: warId, war: warId,
time: getDateTime(budg[5]), time: getDateTime(budg[5]),
fraction: budg[9] === 'NATO' ? 'BLUFOR' : 'OPFOR', fraction: budg[9] === 'NATO' ? 'BLUFOR' : 'OPFOR',
oldBudget: transformMoneyString(budg[11]), oldBudget: transformMoneyString(budg[11]),