Skip to content

Commit

Permalink
try upgrade mongoose
Browse files Browse the repository at this point in the history
  • Loading branch information
virgilchiriac committed Jul 26, 2024
1 parent 1851e7d commit 094741e
Show file tree
Hide file tree
Showing 13 changed files with 146 additions and 65 deletions.
157 changes: 119 additions & 38 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,10 @@
"moment": "^2.19.2",
"mongodb-memory-server-global": "^9.1.8",
"mongodb-uri": "^0.9.7",
"mongoose": "^6.12.3",
"mongoose-delete": "^0.5.4",
"mongoose": "^8.5.1",
"mongoose-delete": "^1.0.2",
"mongoose-id-validator": "^0.6.0",
"mongoose-lean-virtuals": "^0.8.1",
"mongoose-lean-virtuals": "^0.9.1",
"mongoose-shortid-nodeps": "git://github.com/leeroybrun/mongoose-shortid-nodeps.git",
"moodle-client": "^0.5.2",
"nanoid": "^3.3.4",
Expand Down
2 changes: 1 addition & 1 deletion src/services/consent/services/consent.deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ConsentService {
// check for _basonType is need for internal request
// and because of id could also include an $in or simular
// eslint-disable-next-line no-underscore-dangle
if (typeof userId === 'string' || userId._bsontype === 'ObjectID') {
if (typeof userId === 'string' || userId._bsontype === 'ObjectId') {
const user = await this.modelService.get(userId);
return {
total: 1,
Expand Down
6 changes: 3 additions & 3 deletions src/services/fileStorage/proxy-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ const fileStorageService = {
}

return permissionPromise()
.then(() => FileModel.update({ _id }, update).exec())
.then(() => FileModel.updateOne({ _id }, update).exec())
.catch((err) => new Forbidden(err));
},
};
Expand Down Expand Up @@ -690,7 +690,7 @@ const renameService = {
if (!obj) {
return new NotFound('The given directory/file was not found!');
}
return FileModel.update({ _id }, { name: newName }).exec();
return FileModel.updateOne({ _id }, { name: newName }).exec();
})
.catch((err) => new Forbidden(err));
},
Expand Down Expand Up @@ -872,7 +872,7 @@ const filePermissionService = {
}),
];

return FileModel.update(
return FileModel.updateOne(
{ _id },
{
$set: { permissions },
Expand Down
2 changes: 1 addition & 1 deletion src/services/lesson/hooks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ const setPosition = async (context) => {
const { courseId, courseGroupId } = context.data;
if (courseId || courseGroupId) {
const query = courseId ? { courseId } : { courseGroupId };
context.data.position = await LessonModel.count(query).exec(); // next free position
context.data.position = await LessonModel.countDocuments(query).exec(); // next free position
}

return context;
Expand Down
2 changes: 1 addition & 1 deletion src/services/news/hooks/news.hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { newsHistoryModel } = require('../model');

const deleteNewsHistory = async (context) => {
if (context.id) {
await newsHistoryModel.remove({ parentId: context.id });
await newsHistoryModel.deleteOne({ parentId: context.id });
}
return context;
};
Expand Down
2 changes: 1 addition & 1 deletion src/services/role/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const roleSchema = new Schema(
// https://mongoosejs.com/docs/middleware.html
const mongooseOperationsForClearCache = [
'findOneAndDelete',
'findOneAndRemove',
'findOneAndDelete',
'findOneAndUpdate',
'deleteMany',
'deleteOne',
Expand Down
4 changes: 2 additions & 2 deletions src/services/role/utils/permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const ROLES = {
const definePermissions = (env, role, ...permissions) => {
if (Configuration.get(env)) {
// set defaul permission
Role.update(
Role.updateOne(
{
name: role,
},
Expand All @@ -37,7 +37,7 @@ const definePermissions = (env, role, ...permissions) => {
).exec();
} else {
// remove defaul permission
Role.update(
Role.updateOne(
{
name: role,
},
Expand Down
2 changes: 1 addition & 1 deletion src/services/sync/repo/user.repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const updateUser = async (userId, changedUser) => {
};

const deleteUser = async (userId) => {
await userModel.remove({ _id: userId }).lean().exec();
await userModel.deleteOne({ _id: userId }).lean().exec();
};

const findImportUsersBySchoolAndName = async (schoolId, firstName, lastName) => {
Expand Down
8 changes: 4 additions & 4 deletions src/services/user-group/hooks/courses.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const addWholeClassToCourse = async (hook) => {
const userIds = _.flattenDeep(groupUsers).map((groupUser) => groupUser.userId);
const uniqueUserIds = _.uniqWith(userIds, (a, b) => a === b);

await CourseModel.update({ _id: course._id }, { $addToSet: { userIds: { $each: uniqueUserIds } } }).exec();
await CourseModel.updateOne({ _id: course._id }, { $addToSet: { userIds: { $each: uniqueUserIds } } }).exec();

return undefined;
});
Expand All @@ -78,7 +78,7 @@ const addWholeClassToCourse = async (hook) => {
// flatten deep arrays and remove duplicates
studentIds = _.uniqWith(_.flattenDeep(studentIds), (e1, e2) => JSON.stringify(e1) === JSON.stringify(e2));

await CourseModel.update({ _id: course._id }, { $addToSet: { userIds: { $each: studentIds } } }).exec();
await CourseModel.updateOne({ _id: course._id }, { $addToSet: { userIds: { $each: studentIds } } }).exec();

return hook;
});
Expand Down Expand Up @@ -118,7 +118,7 @@ const deleteWholeClassFromCourse = (hook) => {
const userIds = _.flattenDeep(groupUsers).map((groupUser) => groupUser.userId);
const uniqueUserIds = _.uniqWith(userIds, (a, b) => a === b);

await CourseModel.update(
await CourseModel.updateOne(
{ _id: course._id },
{ $pull: { userIds: { $in: uniqueUserIds } } },
{ multi: true }
Expand All @@ -142,7 +142,7 @@ const deleteWholeClassFromCourse = (hook) => {
studentIds = _.uniqWith(_.flattenDeep(studentIds), (e1, e2) => JSON.stringify(e1) === JSON.stringify(e2));

// remove class students from course DB and from hook body to not patch them back
await CourseModel.update(
await CourseModel.updateOne(
{ _id: course._id },
{ $pull: { userIds: { $in: studentIds } } },
{ multi: true }
Expand Down
Loading

0 comments on commit 094741e

Please sign in to comment.