Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- const mongoose = require('mongoose');
- const Schema = mongoose.Schema;
- const ObjectId = Schema.Types.ObjectId;
- const ProductSchema = new Schema({
- description: {
- type: String,
- required: true
- },
- category: {
- type: ObjectId,
- ref: 'Category',
- required: true
- },
- price: {
- type: ObjectId,
- ref: 'Price',
- required: true
- },
- creation_date: {
- type: Date,
- default: new Date()
- }
- });
- ProductSchema.post('validate', doc => {
- if (!doc._id) {
- doc.creation_date = Date.now();
- }
- });
- module.exports = mongoose.model('Product', ProductSchema);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement