This commit is contained in:
21
backend/src/schemas/GridCell.js
Normal file
21
backend/src/schemas/GridCell.js
Normal file
@@ -0,0 +1,21 @@
|
||||
const mongoose = require("mongoose");
|
||||
|
||||
const gridCellSchema = new mongoose.Schema(
|
||||
{
|
||||
x: { type: Number, required: true, min: 1, max: 90 },
|
||||
y: { type: Number, required: true, min: 1, max: 90},
|
||||
color: { type: Number, required: true },
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
gridCellSchema.index({ x: 1, y: 1 }, { unique: true });
|
||||
|
||||
gridCellSchema.methods.toDisplayColor = function () {
|
||||
if (this.color.startsWith("#")) return this.color;
|
||||
return `#${this.color}`;
|
||||
};
|
||||
|
||||
const GridCell = mongoose.model("GridCell", gridCellSchema);
|
||||
|
||||
module.exports = GridCell;
|
||||
Reference in New Issue
Block a user