Skip to content

Instantly share code, notes, and snippets.

@i-van
Created June 25, 2015 10:55
Show Gist options
  • Save i-van/37abf76b79acb46fc71d to your computer and use it in GitHub Desktop.
Save i-van/37abf76b79acb46fc71d to your computer and use it in GitHub Desktop.
const STATUS_CREATED = 'created'
, STATUS_PENDING = 'pending'
, STATUS_STARTED = 'started'
, STATUS_FINISHED = 'finished';
const TYPE_1X1 = '1x1'
, TYPE_2X2 = '2x2';
var mongoose = require('mongoose'),
schema = new mongoose.Schema({
title: String,
host: String,
port: Number,
type: { type: String, default: TYPE_1X1 },
status: { type: String, default: STATUS_CREATED },
online: { type: Number, default: 0 }
});
schema.plugin(require('../plugins/updatable'));
/**
* @returns {Object}
*/
schema.methods.toJSON = function() {
return {
id: this._id,
host: this.host,
port: this.port,
type: this.type,
title: this.title,
status: this.status,
online: this.online
};
};
// constants
schema.statics.STATUS_CREATED = STATUS_CREATED;
schema.statics.STATUS_PENDING = STATUS_PENDING;
schema.statics.STATUS_STARTED = STATUS_STARTED;
schema.statics.STATUS_FINISHED = STATUS_FINISHED;
schema.statics.TYPE_1X1 = TYPE_1X1;
schema.statics.TYPE_2X2 = TYPE_2X2;
schema.statics.TYPES = [TYPE_1X1, TYPE_2X2];
// exports
module.exports = mongoose.model('Game', schema);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment