27 lines
1.1 KiB
JavaScript
27 lines
1.1 KiB
JavaScript
|
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 },
|
||
|
when: { type: Date, required: true },
|
||
|
publicity: { type: Number, required: true, default: 2 },
|
||
|
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 },
|
||
|
createDate: { type: Date, required: true, default: Date.now }
|
||
|
});
|
||
|
|
||
|
export default mongoose.model(ModelNameRegister.Match, matchSchema);
|