opt-cc/server/models/war.js

86 lines
1.6 KiB
JavaScript

'use strict';
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const WarSchema = new Schema({
title: {
type: String,
required: true,
},
date: {
type: Date,
},
endDate: {
type: Date,
},
fractionMappingBlufor: {
type: String,
enum: ['BLUFOR', 'OPFOR', 'ARF', 'SWORD'],
default: 'BLUFOR',
},
fractionMappingOpfor: {
type: String,
enum: ['BLUFOR', 'OPFOR', 'ARF', 'SWORD'],
default: 'OPFOR',
},
ptBlufor: {
type: Number,
get: (v) => Math.round(v),
set: (v) => Math.round(v),
},
ptOpfor: {
type: Number,
get: (v) => Math.round(v),
set: (v) => Math.round(v),
},
playersBlufor: {
type: Number,
get: (v) => Math.round(v),
set: (v) => Math.round(v),
default: 0,
},
playersOpfor: {
type: Number,
get: (v) => Math.round(v),
set: (v) => Math.round(v),
default: 0,
},
campaign: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Campaign',
required: true,
},
budgetBlufor: {
type: Number,
get: (v) => Math.round(v),
set: (v) => Math.round(v),
default: 0,
},
budgetOpfor: {
type: Number,
get: (v) => Math.round(v),
set: (v) => Math.round(v),
default: 0,
},
endBudgetBlufor: {
type: Number,
get: (v) => Math.round(v),
set: (v) => Math.round(v),
default: 0,
},
endBudgetOpfor: {
type: Number,
get: (v) => Math.round(v),
set: (v) => Math.round(v),
default: 0,
},
}, {
collection: 'war',
timestamps: {createdAt: 'timestamp'},
});
// optional more indices
WarSchema.index({timestamp: 1});
module.exports = mongoose.model('War', WarSchema);