mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 06:07:21 +01:00
Mongoose: use $type as the typeKey (#10789)
* use $type as the typeKey in mongoose * fix and add tests
This commit is contained in:
committed by
Sabe Jones
parent
490531cc76
commit
79c0499672
@@ -5,12 +5,13 @@ import validator from 'validator';
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
export let schema = new Schema({
|
||||
_id: {type: String, required: true}, // Use a custom string as _id
|
||||
consumed: {type: Boolean, default: false, required: true},
|
||||
userId: {type: String, ref: 'User', required: true, validate: [v => validator.isUUID(v), 'Invalid uuid.']},
|
||||
_id: {$type: String, required: true}, // Use a custom string as _id
|
||||
consumed: {$type: Boolean, default: false, required: true},
|
||||
userId: {$type: String, ref: 'User', required: true, validate: [v => validator.isUUID(v), 'Invalid uuid.']},
|
||||
}, {
|
||||
strict: true,
|
||||
minimize: false, // So empty objects are returned
|
||||
typeKey: '$type', // So that we can use fields named `type`
|
||||
});
|
||||
|
||||
schema.plugin(baseModel, {
|
||||
|
||||
Reference in New Issue
Block a user