24 lines
638 B
JavaScript
24 lines
638 B
JavaScript
var mongoose = require('mongoose');
|
|
var uniqueValidator = require('mongoose-unique-validator');
|
|
|
|
var MetalSchema = new mongoose.Schema({
|
|
ordering: Number,
|
|
code: { type: String, upercase: true, unique: true },
|
|
title: String,
|
|
color: String,
|
|
image: String
|
|
}, {timestamps: true, toJSON: {virtuals: true}});
|
|
|
|
MetalSchema.plugin(uniqueValidator, { message: 'is already taken' });
|
|
|
|
MetalSchema.methods.toJSONFor = function(){
|
|
return {
|
|
ordering: this.ordering,
|
|
code: this.code,
|
|
title: this.title,
|
|
color: this.color,
|
|
image: this.image
|
|
};
|
|
};
|
|
|
|
mongoose.model('Metal', MetalSchema); |