Harrison Deng
ba566040b1
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.
19 lines
616 B
JavaScript
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); |