models/company.js   A
last analyzed

Complexity

Total Complexity 1
Complexity/F 1

Size

Lines of Code 22
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 22
rs 10
wmc 1
mnd 0
bc 1
fnc 1
bpm 1
cpm 1
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A companySchema.pre(ꞌsaveꞌ) 0 5 1
1
var mongoose = require('mongoose')
2
var addressSchema = require('./common/address')
3
var phoneSchema = require('./common/phone')
4
5
var companySchema = new mongoose.Schema({
6
  name: { type: String, required: true, unique: true },
7
  regNo: { type: String, required: false },
8
  vatNo: { type: String, required: false },
9
  addresses: [addressSchema],
10
  phone: [phoneSchema],
11
  createdOn: { type: Date, default: Date.now },
12
  updatedOn: { type: Date, default: Date.now }
13
})
14
15
// on every save, add the date
16
companySchema.pre('save', function (next) {
17
  // change the updated_at field to current date
18
  this.updatedOn = new Date()
19
  next()
20
})
21
22
module.exports = mongoose.model('Company', companySchema)
23