-
-
Save pantchox/f1df06ca8db98e9cf30af9032da54bc4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mongoose, { Schema } from 'mongoose' | |
const bookListsSchema = new Schema({ | |
// sub resources ref fields | |
books: [{ | |
type: Schema.ObjectId, | |
ref: 'Books' | |
}], | |
// normal entity fields | |
user: { | |
type: Schema.ObjectId, | |
ref: 'User', | |
required: true | |
}, | |
title: { | |
type: String, | |
required: true | |
} | |
}, { | |
timestamps: true | |
}) | |
bookListsSchema.methods = { | |
view () { | |
return = { | |
// simple view | |
id: this.id, | |
user: this.user.view(full), | |
books: this.books.map((books) => books.view()), | |
title: this.title, | |
createdAt: this.createdAt, | |
updatedAt: this.updatedAt | |
} | |
} | |
} | |
const model = mongoose.model('BookLists', cardListsSchema) | |
export const schema = model.schema | |
export default model |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment