Skip to content

Commit

Permalink
fix mongoose and upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
paglias committed Oct 18, 2018
1 parent ffba435 commit ed562e7
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 65 deletions.
120 changes: 80 additions & 40 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"method-override": "^2.3.5",
"moment": "^2.22.1",
"moment-recur": "^1.0.7",
"mongoose": "^5.1.3",
"mongoose": "^5.3.4",
"morgan": "^1.7.0",
"nconf": "^0.10.0",
"node-gcm": "^0.14.4",
Expand Down
4 changes: 2 additions & 2 deletions website/server/models/challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ let schema = new Schema({
todos: [{type: String, ref: 'Task'}],
rewards: [{type: String, ref: 'Task'}],
},
leader: {type: String, ref: 'User', validate: [validator.isUUID, 'Invalid uuid.'], required: true},
group: {type: String, ref: 'Group', validate: [validator.isUUID, 'Invalid uuid.'], required: true},
leader: {type: String, ref: 'User', validate: [v => validator.isUUID(v), 'Invalid uuid.'], required: true},
group: {type: String, ref: 'Group', validate: [v => validator.isUUID(v), 'Invalid uuid.'], required: true},
memberCount: {type: Number, default: 0},
prize: {type: Number, default: 0, min: 0},
categories: [{
Expand Down
2 changes: 1 addition & 1 deletion website/server/models/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export let schema = new Schema({
name: {type: String, required: true},
summary: {type: String, maxlength: MAX_SUMMARY_SIZE_FOR_GUILDS},
description: String,
leader: {type: String, ref: 'User', validate: [validator.isUUID, 'Invalid uuid.'], required: true},
leader: {type: String, ref: 'User', validate: [v => validator.isUUID(v), 'Invalid uuid.'], required: true},
type: {type: String, enum: ['guild', 'party'], required: true},
privacy: {type: String, enum: ['private', 'public'], default: 'private', required: true},
chat: Array, // Used for backward compatibility, but messages aren't stored here
Expand Down
2 changes: 1 addition & 1 deletion website/server/models/iapPurchaseReceipt.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ 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: [validator.isUUID, 'Invalid uuid.']},
userId: {type: String, ref: 'User', required: true, validate: [v => validator.isUUID(v), 'Invalid uuid.']},
}, {
strict: true,
minimize: false, // So empty objects are returned
Expand Down
2 changes: 1 addition & 1 deletion website/server/models/subscriptionPlan.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import validator from 'validator';
export let schema = new mongoose.Schema({
planId: String,
subscriptionId: String,
owner: {type: String, ref: 'User', validate: [validator.isUUID, 'Invalid uuid.']},
owner: {type: String, ref: 'User', validate: [v => validator.isUUID(v), 'Invalid uuid.']},
quantity: {type: Number, default: 1},
paymentMethod: String, // enum: ['Paypal', 'Stripe', 'Gift', 'Amazon Payments', 'Google', '']}
customerId: String, // Billing Agreement Id in case of Amazon Payments
Expand Down
2 changes: 1 addition & 1 deletion website/server/models/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export let schema = new Schema({
id: {
type: String,
default: uuid,
validate: [validator.isUUID, 'Invalid uuid.'],
validate: [v => validator.isUUID(v), 'Invalid uuid.'],
required: true,
},
name: {type: String, required: true},
Expand Down
20 changes: 10 additions & 10 deletions website/server/models/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export let TaskSchema = new Schema({
},
tags: [{
type: String,
validate: [validator.isUUID, 'Invalid uuid.'],
validate: [v => validator.isUUID(v), 'Invalid uuid.'],
}],
value: {type: Number, default: 0, required: true}, // redness or cost for rewards Required because it must be settable (for rewards)
priority: {
Expand All @@ -89,26 +89,26 @@ export let TaskSchema = new Schema({
],
},
attribute: {type: String, default: 'str', enum: ['str', 'con', 'int', 'per']},
userId: {type: String, ref: 'User', validate: [validator.isUUID, 'Invalid uuid.']}, // When not set it belongs to a challenge
userId: {type: String, ref: 'User', validate: [v => validator.isUUID(v), 'Invalid uuid.']}, // When not set it belongs to a challenge

challenge: {
shortName: {type: String},
id: {type: String, ref: 'Challenge', validate: [validator.isUUID, 'Invalid uuid.']}, // When set (and userId not set) it's the original task
taskId: {type: String, ref: 'Task', validate: [validator.isUUID, 'Invalid uuid.']}, // When not set but challenge.id defined it's the original task
id: {type: String, ref: 'Challenge', validate: [v => validator.isUUID(v), 'Invalid uuid.']}, // When set (and userId not set) it's the original task
taskId: {type: String, ref: 'Task', validate: [v => validator.isUUID(v), 'Invalid uuid.']}, // When not set but challenge.id defined it's the original task
broken: {type: String, enum: ['CHALLENGE_DELETED', 'TASK_DELETED', 'UNSUBSCRIBED', 'CHALLENGE_CLOSED', 'CHALLENGE_TASK_NOT_FOUND']}, // CHALLENGE_TASK_NOT_FOUND comes from v3 migration
winner: String, // user.profile.name of the winner
},

group: {
id: {type: String, ref: 'Group', validate: [validator.isUUID, 'Invalid uuid.']},
id: {type: String, ref: 'Group', validate: [v => validator.isUUID(v), 'Invalid uuid.']},
broken: {type: String, enum: ['GROUP_DELETED', 'TASK_DELETED', 'UNSUBSCRIBED']},
assignedUsers: [{type: String, ref: 'User', validate: [validator.isUUID, 'Invalid uuid.']}],
taskId: {type: String, ref: 'Task', validate: [validator.isUUID, 'Invalid uuid.']},
assignedUsers: [{type: String, ref: 'User', validate: [v => validator.isUUID(v), 'Invalid uuid.']}],
taskId: {type: String, ref: 'Task', validate: [v => validator.isUUID(v), 'Invalid uuid.']},
approval: {
required: {type: Boolean, default: false},
approved: {type: Boolean, default: false},
dateApproved: {type: Date},
approvingUser: {type: String, ref: 'User', validate: [validator.isUUID, 'Invalid uuid.']},
approvingUser: {type: String, ref: 'User', validate: [v => validator.isUUID(v), 'Invalid uuid.']},
requested: {type: Boolean, default: false},
requestedDate: {type: Date},
},
Expand All @@ -117,7 +117,7 @@ export let TaskSchema = new Schema({

reminders: [{
_id: false,
id: {type: String, validate: [validator.isUUID, 'Invalid uuid.'], default: shared.uuid, required: true},
id: {type: String, validate: [v => validator.isUUID(v), 'Invalid uuid.'], default: shared.uuid, required: true},
startDate: {type: Date},
time: {type: Date, required: true},
}],
Expand Down Expand Up @@ -265,7 +265,7 @@ let dailyTodoSchema = () => {
completed: {type: Boolean, default: false},
text: {type: String, required: false, default: ''}, // required:false because it can be empty on creation
_id: false,
id: {type: String, default: shared.uuid, required: true, validate: [validator.isUUID, 'Invalid uuid.']},
id: {type: String, default: shared.uuid, required: true, validate: [v => validator.isUUID(v), 'Invalid uuid.']},
linkId: {type: String},
}],
};
Expand Down
12 changes: 6 additions & 6 deletions website/server/models/user/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ let schema = new Schema({
email: {
type: String,
validate: [{
validator: validator.isEmail,
validator: (v) => validator.isEmail(v),
message: shared.i18n.t('invalidEmail'),
}, {
validator (email) {
Expand Down Expand Up @@ -374,7 +374,7 @@ let schema = new Schema({
return {};
}},

challenges: [{type: String, ref: 'Challenge', validate: [validator.isUUID, 'Invalid uuid.']}],
challenges: [{type: String, ref: 'Challenge', validate: [v => validator.isUUID(v), 'Invalid uuid.']}],

invitations: {
// Using an array without validation because otherwise mongoose treat this as a subdocument and applies _id by default
Expand All @@ -391,7 +391,7 @@ let schema = new Schema({
type: String,
ref: 'Group',
required: true,
validate: [validator.isUUID, 'Invalid uuid.'],
validate: [v => validator.isUUID(v), 'Invalid uuid.'],
},
name: {
type: String,
Expand All @@ -401,15 +401,15 @@ let schema = new Schema({
type: String,
ref: 'User',
required: true,
validate: [validator.isUUID, 'Invalid uuid.'],
validate: [v => validator.isUUID(v), 'Invalid uuid.'],
},
}],
},

guilds: [{type: String, ref: 'Group', validate: [validator.isUUID, 'Invalid uuid.']}],
guilds: [{type: String, ref: 'Group', validate: [v => validator.isUUID(v), 'Invalid uuid.']}],

party: {
_id: {type: String, validate: [validator.isUUID, 'Invalid uuid.'], ref: 'Group'},
_id: {type: String, validate: [v => validator.isUUID(v), 'Invalid uuid.'], ref: 'Group'},
order: {type: String, default: 'level'},
orderAscending: {type: String, default: 'ascending'},
quest: {
Expand Down
2 changes: 1 addition & 1 deletion website/server/models/userNotification.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export let schema = new Schema({
id: {
type: String,
default: uuid,
validate: [validator.isUUID, 'Invalid uuid.'],
validate: [v => validator.isUUID(v), 'Invalid uuid.'],
// @TODO: Add these back once we figure out the issue with notifications
// See Fix for https://github.com/HabitRPG/habitica/issues/9923
// required: true,
Expand Down
2 changes: 1 addition & 1 deletion website/server/models/webhook.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export let schema = new Schema({
id: {
type: String,
required: true,
validate: [validator.isUUID, shared.i18n.t('invalidWebhookId')],
validate: [v => validator.isUUID(v), shared.i18n.t('invalidWebhookId')],
default: uuid,
},
type: {
Expand Down

0 comments on commit ed562e7

Please sign in to comment.