import mongoose from "mongoose"; import ModelNameRegister from "./modelNameRegister.js"; const sportSchema = new mongoose.Schema({ name: { type: String, required: true, unique: true, trim: true }, minPlayers: { type: Number, required: true, default: 1 }, description: { type: String, required: true, trim: true } }); sportSchema.pre("save", function (next) { this.name = this.name.toLowerCase(); next(); }); sportSchema.statics.findByName = function (name) { return this.findOne({ name: name.trim().toLowerCase() }); }; export default mongoose.model(ModelNameRegister.Sport, sportSchema);