Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | 4x 4x 4x 4x 4x | const mongoose = require('mongoose')
const reviewSchema = new mongoose.Schema({
user: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true },
description: { type: String },
rating: {
type: Number,
min: [1, 'Rating must be at least 1.'],
max: [5, 'Rating cannot exceed 5.'],
},
})
const bookSchema = new mongoose.Schema(
{
title: { type: String, required: [true, 'Title is required.'] },
description: { type: String, required: true },
coverImage: { type: String },
author: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Author',
required: [true, 'Author is required.'],
},
categories: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Category' }],
price: {
type: Number,
required: [true, 'Price is required.'],
min: [0, 'Price cannot be negative.'],
},
review: [reviewSchema],
},
{ timestamps: true },
)
const BookModel = mongoose.model('Book', bookSchema)
module.exports = BookModel
|