Skip to content

Commit

Permalink
feat(lelouchB#143): create quotes model
Browse files Browse the repository at this point in the history
  • Loading branch information
Mayank0255 committed Nov 17, 2020
1 parent 4a0b007 commit 4706411
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Logs
/.idea
logs
*.log
npm-debug.log*
Expand Down Expand Up @@ -69,7 +70,7 @@ typings/
.yarn-integrity

# dotenv environment variables file
.env
backend/.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
Expand Down
48 changes: 48 additions & 0 deletions backend/models/quote.model.js
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4706411

Please sign in to comment.