Mongoose: use $type as the typeKey (#10789)

* use $type as the typeKey in mongoose

* fix and add tests
This commit is contained in:
Matteo Pagliazzi
2018-10-28 15:23:41 +01:00
committed by Sabe Jones
parent 490531cc76
commit 79c0499672
15 changed files with 383 additions and 357 deletions

View File

@@ -37,7 +37,7 @@ const Schema = mongoose.Schema;
export let schema = new Schema({
id: {
type: String,
$type: String,
default: uuid,
validate: [v => validator.isUUID(v), 'Invalid uuid.'],
// @TODO: Add these back once we figure out the issue with notifications
@@ -45,25 +45,26 @@ export let schema = new Schema({
// required: true,
},
type: {
type: String,
$type: String,
// @TODO: Add these back once we figure out the issue with notifications
// See Fix for https://github.com/HabitRPG/habitica/issues/9923
// required: true,
enum: NOTIFICATION_TYPES,
},
data: {type: Schema.Types.Mixed, default: () => {
data: {$type: Schema.Types.Mixed, default: () => {
return {};
}},
// A field to mark the notification as seen without deleting it, optional use
seen: {
type: Boolean,
$type: Boolean,
// required: true,
default: () => false,
},
}, {
strict: true,
minimize: false, // So empty objects are returned
_id: false, // use id instead of _id
_id: false, // use id instead of _id,
typeKey: '$type', // So that we can use fields named `type`
});
/**