diff --git a/.gitignore b/.gitignore index 6704566..2ea5e5f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ # Logs +/.idea logs *.log npm-debug.log* @@ -69,7 +70,7 @@ typings/ .yarn-integrity # dotenv environment variables file -.env +backend/.env .env.test # parcel-bundler cache (https://parceljs.org/) diff --git a/backend/models/quote.model.js b/backend/models/quote.model.js new file mode 100644 index 0000000..5e990ff --- /dev/null +++ b/backend/models/quote.model.js @@ -0,0 +1,48 @@ +const mongoose = require("mongoose") + +const quoteSchema = new mongoose.Schema( + { + id: { + type: Number, + unique: true, + }, + quote: { + type: String, + default: "", + }, + by: { + type: String, + default: "", + }, + character: { + type: String, + default: "", + }, + image: { + type: String, + default: "", + }, + }, + { + collection: "quotes", + }, + { + timestamps: true, + }, +) + +quoteSchema.statics.structure = (res) => { + const sortSchema = ({ id, quote, by, character, image }) => ({ + id, + quote, + by, + character, + image, + }) + + return Array.isArray(res) ? res.map(sortSchema) : sortSchema(res) +} + +const Quote = mongoose.model("quotes", quoteSchema) + +module.exports = Quote