Repository navigation
Expand file tree
/
Copy pathequipment.js
More file actions
131 lines (119 loc) · 3.72 KB
/
Copy pathequipment.js
File metadata and controls
131 lines (119 loc) · 3.72 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
const mongoose = require('mongoose');
const uniqueValidator = require('mongoose-unique-validator');
const addHistory = require('mongoose-history');
const historyOptions = { diffOnly: true };
// Equipment
const equipRMASchema = mongoose.Schema({
equipRMAOpened: Date,
equipRMAClosed: Date,
equipRMANumber: String,
equipRMANotes: String,
equipRMATicket: String,
createdBy: String,
modifiedBy: String,
},
{ timestamps: { createdAt: 'createdOn', updatedAt: 'modifiedOn' },
});
const equipPortSchema = mongoose.Schema({
equipPortType: String,
equipPortsAddr: { type: String, unique: true, sparse: true },
equipPortName: String,
equipPortsOpt: String,
createdBy: String,
modifiedBy: String,
},
{ timestamps: { createdAt: 'createdOn', updatedAt: 'modifiedOn' },
});
const equipmentSchema = mongoose.Schema({
equipLocation: { type: String, index: 1 },
equipSN: { type: String, unique: true, index: 1, sparse: true, required: true },
equipAssetTag: String,
equipRMAs: [equipRMASchema],
equipPorts: [equipPortSchema],
equipTicketNumber: String,
equipInventoryStatus: { type: Boolean },
equipStatus: String,
equipIsVirtual: { type: Boolean, default: false },
equipEOL: { type: Boolean, default: false, index: 1 },
equipTemplate: { type: Boolean, default: false },
equipLOB: { type: String, index: 1 },
equipType: String,
equipMake: { type: String, index: 1 },
equipModel: String,
equipSubModel: String,
equipRUHieght: Number,
equipParent: String,
equipImgFront: String,
equipImgRear: String,
equipImgInternal: String,
equipFirmware: String,
equipIPMIv: String,
equipMobo: String,
equipCPUCount: Number,
equipCPUCores: Number,
equipCPUType: String,
equipMemType: String,
equipMemTotal: String,
equipRaidType: String,
equipRaidLayout: String,
equipHDDCount: String,
equipHDDType: String,
equipNICCount: Number,
equipNICType: String,
equipPSUCount: Number,
equipPSUDraw: Number,
equipAddOns: String,
equipReceived: { type: Date },
equipAcquisition: Date,
equipInService: Date,
equipEndOfLife: Date,
equipWarrantyMo: Number,
equipPONum: String,
equipInvoice: String,
equipProjectNum: String,
equipLicense: String,
equipMaintAgree: String,
equipPurchaseType: String,
equipPurchaser: String,
equipPurchaseTerms: String,
equipPurchaseEnd: Date,
equipNotes: String,
createdBy: String,
modifiedBy: String,
},
{ timestamps: { createdAt: 'createdOn', updatedAt: 'modifiedOn' },
});
equipmentSchema.pre('save', function (next) {
var currentDate = new Date();
if (this.equipEOL === true) {
this.equipLocation = null;
if (!this.equipEndOfLife) {
this.equipEndOfLife = currentDate;
}
}
next();
});
// Apply the uniqueValidator plugin to datacenterSchema
equipmentSchema.plugin(uniqueValidator);
// equipmentSchema.plugin(uniqueValidator, { message: 'Error, expected {PATH} to be unique.' });
equipmentSchema.virtual('equipLocRack').get(function () {
if (this.equipLocation) {
var cutLine = this.equipLocation.lastIndexOf('_');
return this.equipLocation.substring(0, cutLine);
}
return undefined;
});
equipmentSchema.virtual('equipLocRU').get(function () {
if (this.equipLocation) {
var cutLine = this.equipLocation.lastIndexOf('_');
return this.equipLocation.slice(cutLine + 1);
}
return undefined;
});
equipmentSchema.virtual('dcAbbr').get(function() {
var start = this.equipLocation.indexOf('-');
return this.equipLocation.substring(start + 1);
});
equipmentSchema.plugin(addHistory, historyOptions);
const Equipment = mongoose.model('Equipment', equipmentSchema);
module.exports = Equipment;