app/models/book.js   A
last analyzed

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 43
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 1
dl 0
loc 43
rs 10
wmc 2
mnd 1
bc 2
fnc 1
bpm 2
cpm 2
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A book.js ➔ ??? 0 7 2
1
'use strict';
2
const mongoose = require('mongoose');
3
const Schema = mongoose.Schema;
4
5
// Boook schema definition
6
7
const BookSchema = new Schema({
8
    title: {
9
        type: String,
10
        required: true
11
    },
12
    author: {
13
        type: String,
14
        required: true
15
    },
16
    year: {
17
        type: Number,
18
        required: true
19
    },
20
    pages: {
21
        type: Number,
22
        required: true
23
    },
24
    createdAt: {
25
        type: Date,
26
        default: Date.now
27
    }
28
}, {
29
    versionKey: false
30
});
31
32
// Sets the createdAt parameter equal to the current time
33
34
BookSchema.pre('save', next => {
35
    const now = new Date();
36
    if (!this.createdAt) {
37
        this.createdAt = now;
38
    }
39
    next();
40
});
41
42
// Exports the BookSchema for use elsewhere
43
module.exports = mongoose.model('book', BookSchema);