Upgrade to mongoose 7 (#14971)

* remove some unused dependencies

* update mongoose version

* make common tests pass

* Make unit tests pass

* make api v3 integration tests pass

* fix lint issues

* fix issue with package-lock

* fix(lint): we don't need no .js

* fix(lint): update to latest config-habitrpg

* chore(npm): update package locks

* fix(test): replace deprecated fn

* chore(package): update eslint-habitrpg again

* fix(lint): server linting

* fix(lint): client linting

* fix(client): correct mangled common imports

* chore(npm): update package-locks

* fix(lint): punctuation, module

---------

Co-authored-by: SabreCat <sabrecat@gmail.com>
Co-authored-by: SabreCat <sabe@habitica.com>
This commit is contained in:
Phillip Thelen
2024-01-16 22:18:47 +01:00
committed by GitHub
parent d0e4b533e3
commit f8d315ff6e
189 changed files with 2645 additions and 1423 deletions

View File

@@ -351,15 +351,17 @@ api.resetPassword = {
{ auth: 1 },
).exec();
if (!user) { // If no local auth with that email...
const potentialUsers = await User.find({
$or: [
{ 'auth.local.username': email.replace(/^@/, '') },
{ 'auth.apple.emails.value': email },
{ 'auth.google.emails.value': email },
{ 'auth.facebook.emails.value': email },
],
},
{ auth: 1 }).exec();
const potentialUsers = await User.find(
{
$or: [
{ 'auth.local.username': email.replace(/^@/, '') },
{ 'auth.apple.emails.value': email },
{ 'auth.google.emails.value': email },
{ 'auth.facebook.emails.value': email },
],
},
{ auth: 1 },
).exec();
// ...prefer oldest social account or username with matching email
[user] = sortBy(potentialUsers, candidate => candidate.auth.timestamps.created);
}
@@ -512,7 +514,7 @@ api.deleteSocial = {
const unset = {
[`auth.${network}`]: 1,
};
await User.update({ _id: user._id }, { $unset: unset }).exec();
await User.updateOne({ _id: user._id }, { $unset: unset }).exec();
res.respond(200, {});
},

View File

@@ -777,7 +777,8 @@ api.exportChallengeCsv = {
// repeated n times for the n challenge tasks
const challengeTasks = _.reduce(
challenge.tasksOrder.toObject(),
(result, array) => result.concat(array), [],
(result, array) => result.concat(array),
[],
).sort();
resArray.unshift(['UUID', 'Display Name', 'Username']);

View File

@@ -418,7 +418,7 @@ api.seenChat = {
// See https://github.com/HabitRPG/habitica/pull/9321#issuecomment-354187666 for more info
user._v += 1;
await User.update({ _id: user._id }, update).exec();
await User.updateOne({ _id: user._id }, update).exec();
res.respond(200, {});
},
};
@@ -478,7 +478,7 @@ api.deleteChat = {
lastClientMsg && group.chat && group.chat[0] && group.chat[0].id !== lastClientMsg
);
await Chat.remove({ _id: message._id }).exec();
await Chat.deleteOne({ _id: message._id }).exec();
if (chatUpdated) {
removeFromArray(chatRes.chat, { id: chatId });

View File

@@ -672,7 +672,7 @@ api.joinGroup = {
if (group.memberCount > 1) {
const notification = new UserNotification({ type: 'ACHIEVEMENT_PARTY_UP' });
promises.push(User.update(
promises.push(User.updateMany(
{
$or: [{ 'party._id': group._id }, { _id: user._id }],
'achievements.partyUp': { $ne: true },
@@ -682,7 +682,6 @@ api.joinGroup = {
$set: { 'achievements.partyUp': true },
$push: { notifications: notification.toObject() },
},
{ multi: true },
).exec());
if (inviter) {
@@ -696,7 +695,7 @@ api.joinGroup = {
if (group.memberCount > 3) {
const notification = new UserNotification({ type: 'ACHIEVEMENT_PARTY_ON' });
promises.push(User.update(
promises.push(User.updateMany(
{
$or: [{ 'party._id': group._id }, { _id: user._id }],
'achievements.partyOn': { $ne: true },
@@ -706,7 +705,6 @@ api.joinGroup = {
$set: { 'achievements.partyOn': true },
$push: { notifications: notification.toObject() },
},
{ multi: true },
).exec());
if (inviter) {

View File

@@ -299,7 +299,9 @@ api.updateHero = {
if (changedHourglassTrinkets !== 0) {
await hero.updateHourglasses(
changedHourglassTrinkets,
'admin_update_hourglasses', '', 'Updated by Habitica staff',
'admin_update_hourglasses',
'',
'Updated by Habitica staff',
);
}

View File

@@ -756,13 +756,15 @@ api.transferGems = {
]);
}
if (receiver.preferences.pushNotifications.giftedGems !== false) {
sendPushNotification(receiver,
sendPushNotification(
receiver,
{
title: res.t('giftedGems', receiverLang),
message: res.t('giftedGemsInfo', { amount: gemAmount, name: byUsername }, receiverLang),
identifier: 'giftedGems',
payload: { replyTo: sender._id },
});
},
);
}
res.respond(200, {});

View File

@@ -42,7 +42,7 @@ api.readNotification = {
// See https://github.com/HabitRPG/habitica/pull/9321#issuecomment-354187666 for more info
user._v += 1;
await user.update({
await user.updateOne({
$pull: { notifications: { id: req.params.notificationId } },
}).exec();
@@ -80,7 +80,7 @@ api.readNotifications = {
user.notifications.splice(index, 1);
}
await user.update({
await user.updateOne({
$pull: { notifications: { id: { $in: notificationsIds } } },
}).exec();
@@ -127,7 +127,7 @@ api.seeNotification = {
notification.seen = true;
await User.update({
await User.updateOne({
_id: user._id,
'notifications.id': notificationId,
}, {

View File

@@ -46,7 +46,7 @@ api.addPushDevice = {
// Concurrency safe update
const pushDevice = (new PushDevice(item)).toJSON(); // Create a mongo doc
await user.update({
await user.updateOne({
$push: { pushDevices: pushDevice },
}).exec();
@@ -92,7 +92,7 @@ api.removePushDevice = {
// Concurrency safe update
const pullQuery = { $pull: { pushDevices: { regId } } };
await user.update(pullQuery).exec();
await user.updateOne(pullQuery).exec();
// Update the response
pushDevices.splice(indexOfPushDevice, 1);

View File

@@ -1266,7 +1266,7 @@ api.unlinkAllTasks = {
removeFromArray(user.tasksOrder[`${task.type}s`], task._id);
}
toSave.push(task.remove());
toSave.push(task.deleteOne());
});
toSave.push(user.save());
@@ -1322,9 +1322,9 @@ api.unlinkOneTask = {
} else { // remove
if (task.type !== 'todo' || !task.completed) { // eslint-disable-line no-lonely-if
removeFromArray(user.tasksOrder[`${task.type}s`], taskId);
await Promise.all([user.save(), task.remove()]);
await Promise.all([user.save(), task.deleteOne()]);
} else {
await task.remove();
await task.deleteOne();
}
}
@@ -1356,7 +1356,7 @@ api.clearCompletedTodos = {
// Clear completed todos
// Do not delete completed todos from challenges or groups, unless the task is broken
await Tasks.Task.remove({
await Tasks.Task.deleteMany({
userId: user._id,
type: 'todo',
completed: true,
@@ -1440,9 +1440,9 @@ api.deleteTask = {
// See https://github.com/HabitRPG/habitica/pull/9321#issuecomment-354187666 for more info
if (!challenge) user._v += 1;
await Promise.all([taskOrderUpdate, task.remove()]);
await Promise.all([taskOrderUpdate, task.deleteOne()]);
} else {
await task.remove();
await task.deleteOne();
}
res.respond(200, {});

View File

@@ -175,7 +175,7 @@ api.groupMoveTask = {
}
const fixQuery = { $set: {} };
fixQuery.$set[`tasksOrder.${task.type}s`] = order;
await group.update(fixQuery).exec();
await group.updateOne(fixQuery).exec();
}
moveTask(order, task._id, to);

View File

@@ -304,11 +304,11 @@ api.deleteUser = {
await Promise.all(groupLeavePromises);
await Tasks.Task.remove({
await Tasks.Task.deleteMany({
userId: user._id,
}).exec();
await user.remove();
await user.deleteOne();
if (feedback) {
sendTxn({ email: TECH_ASSISTANCE_EMAIL }, 'admin-feedback', [