-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathentry.model.js
54 lines (48 loc) · 1.28 KB
/
entry.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import mongoose from 'mongoose';
import { generateRssForReading } from '../helpers/rss.js';
import db from './db.js';
export const EntrySchema = {
title: { type: String, required: true },
author: String,
date: { type: String, required: true, match: /^\d{4}(-\d{2}){0,2}$/ },
work: String,
publisher: String,
workItalics: Boolean,
preposition: String,
parenthetical: String,
href: { type: String, match: /^https?/ },
tags: [
{
type: mongoose.Schema.Types.ObjectId,
ref: 'Tag',
},
],
entryAdded: Date,
};
const ShortformBaseSchema = {
...EntrySchema,
started: { type: String, required: true, match: /^\d{4}(-\d{2}){0,2}$/ },
completed: { type: String, required: false, match: /^\d{4}(-\d{2}){0,2}$/ },
status: {
type: String,
enum: ['read', 'currentlyReading', 'reference', 'shelved', 'toRead'],
},
relatedReading: [String],
};
const ShortformSchema = new mongoose.Schema({
...ShortformBaseSchema,
summary: String,
});
ShortformSchema.post('save', async () => {
await generateRssForReading();
});
export const ShortformEntry = db.readingListConnection.model(
'ShortformEntry',
ShortformSchema,
'shortform',
);
export const PressEntry = db.readingListConnection.model(
'PressEntry',
new mongoose.Schema(EntrySchema),
'press',
);