-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbook.model.js
39 lines (37 loc) · 1.02 KB
/
book.model.js
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
37
38
39
import mongoose from 'mongoose';
import db from './db.js';
export const BookSchema = new mongoose.Schema(
{
title: { type: String, required: true },
subtitle: String,
author: String,
editor: String,
translator: String,
format: { type: String, enum: ['print', 'digital', 'audio'] },
date: { type: String, required: true, match: /^\d{4}(-\d{2}){0,2}$/ },
publisher: String,
imageSrc: String,
href: String,
started: { type: String, match: /^\d{4}-\d{2}-\d{2}$/ },
completed: { type: String, match: /^\d{4}-\d{2}-\d{2}$/ },
status: {
type: String,
enum: ['read', 'currentlyReading', 'dnf', 'reference', 'toRead'],
},
pages: Number,
series: String,
seriesNumber: Number,
stars: Number,
tags: [
{
type: mongoose.Schema.Types.ObjectId,
ref: 'Tag',
},
],
fiction: Boolean,
border: Boolean,
entryAdded: Date,
},
{ timestamps: true },
);
export const Book = db.readingListConnection.model('Book', BookSchema, 'books');