Files
Jeobeardy/src/server/models/BoardModel.js
T

25 lines
863 B
JavaScript
Raw Normal View History

2023-07-10 18:18:02 +02:00
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const BoardSchema = new Schema({
ownerId: { type: Schema.Types.ObjectId, ref: "User", required: true },
name: { type: String, required: true, maxLength: 100 },
categories: { type: [Object], required: false, default: [] },
2026-05-01 17:39:21 +02:00
options: { type: Object, required: true, default: { losePointsOnWrong: false, lossMultiplier: 1, onlyOnBuzzer: true } }
2023-07-10 18:18:02 +02:00
});
// Virtual for player's URL
BoardSchema.virtual("url").get(function () {
// We don't use an arrow function as we'll need the this object
return `/board/${this._id}`;
});
BoardSchema.virtual("setFromPostObject").set( function( postObject ){
this.name = postObject.boardName;
this.categories = postObject.categories;
2026-05-01 17:39:21 +02:00
this.options = postObject.options;
2023-07-10 18:18:02 +02:00
})
// Export model
module.exports = mongoose.model("Board", BoardSchema);