Files
habitica/website/server/models/emailUnsubscription.js
Matteo Pagliazzi 79c0499672 Mongoose: use $type as the typeKey (#10789)
* use $type as the typeKey in mongoose

* fix and add tests
2018-10-28 15:42:48 -05:00

26 lines
677 B
JavaScript

import mongoose from 'mongoose';
import validator from 'validator';
import baseModel from '../libs/baseModel';
// A collection used to store mailing list unsubscription for non registered email addresses
export let schema = new mongoose.Schema({
email: {
$type: String,
required: true,
trim: true,
lowercase: true,
validator: [v => validator.isEmail(v), 'Invalid email.'],
},
}, {
strict: true,
minimize: false, // So empty objects are returned
typeKey: '$type', // So that we can use fields named `type`
});
schema.plugin(baseModel, {
noSet: ['_id'],
timestamps: true,
});
export let model = mongoose.model('EmailUnsubscription', schema);