app/models/author.js   A
last analyzed

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 41
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

1 Function

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