sports-matcher/server/schemas/matchModel.js

26 lines
1021 B
JavaScript
Raw Normal View History

2022-04-01 10:29:20 +00:00
import mongoose from "mongoose";
import ModelNameRegister from "./ModelNameRegister.js";
const Types = mongoose.Schema.Types; // Some types require defining from this object.
const matchSchema = new mongoose.Schema({
title: { type: String, required: true, trim: true },
dateTime: { type: Date, required: true },
public: { type: Boolean, required: true, default: true },
location: {
type: [Number],
required: true,
validate: {
validator: function (v) {
return v.length === 2;
},
message: "Invalid coordinate format (array not length of 2)"
}
},
creator: { type: Types.ObjectId, ref: ModelNameRegister.User },
participants: { type: [{ type: Types.ObjectId, ref: ModelNameRegister.User }], required: true, default: [] },
difficulty: { type: Number, required: true },
sport: { type: Types.ObjectId, ref: ModelNameRegister.Sport }
});
export default mongoose.model(ModelNameRegister.Match, matchSchema);