generated from TeamMrWeb/graphql-mongoose-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPaste.js
53 lines (50 loc) · 1.12 KB
/
Paste.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
const { Schema, model, connection } = require('mongoose')
const pasteSchema = new Schema(
{
title: {
type: String,
required: true,
minlength: 5,
maxlength: 30,
},
content: {
type: String,
required: true,
minlength: 8,
maxlength: 1000,
},
syntax_highlight: {
type: String,
required: true,
},
tags: {
type: [String],
required: true,
},
views: {
type: Number,
required: true,
default: 0,
},
private: {
type: Boolean,
required: true,
},
author: {
type: Schema.Types.ObjectId,
ref: 'User',
required: true,
},
},
{
versionKey: false,
timestamps: true,
},
)
pasteSchema.virtual('storage_size').get(function () {
return connection.db.command({
storageSize: this.collection.name,
size: true,
})
})
module.exports = model('Paste', pasteSchema)