csc309-team58/sports-matcher/server/schemas/sportModel.js
Harrison Deng ba566040b1 Rewrite phase 1.
Started improved client code structure.

Implemented session based authentication serverside.

Implemented user, match, and sport database models serverside.

Implemented Controllers for variety of C and R operations of CRUD.
2022-04-04 20:15:43 -05:00

19 lines
616 B
JavaScript

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);