nodejs-rigorous
Version:
Rigorous Framework
37 lines (27 loc) • 992 B
JavaScript
module.exports = (mongoose, attributesSettings) => {
// Schema
const collectionRules = {};
Object.keys(attributesSettings).forEach((key) => { collectionRules[key] = attributesSettings[key].schema; });
const objectCollectionSchema = new mongoose.Schema(
collectionRules,
{
timestamps: { createdAt: 'created_at', updatedAt: 'updated_at' },
toObject: {
virtuals: true,
transform: function (doc, ret, options) {
ret.id = ret._id;
delete ret._id;
},
},
toJSON: { virtuals: true,
transform: function (doc, ret, options) {
ret.id = ret._id;
delete ret._id;
delete ret.__v;
return ret;
},
},
},
);
return objectCollectionSchema;
};