mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 06:37:23 +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:
@@ -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`
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user