Skip to content

Commit

Permalink
Mongoose: solving more of depreciation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
tima101 committed Oct 12, 2018
1 parent 22e4b9f commit 6bbe205
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
9 changes: 7 additions & 2 deletions api/server/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,16 @@ const ROOT_URL = dev ? `http://localhost:${port}` : PRODUCTION_URL_API;

const MONGO_URL = dev ? process.env.MONGO_URL_TEST : process.env.MONGO_URL;

const options = {
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
};

mongoose.connect(
MONGO_URL,
{ useNewUrlParser: true, useFindAndModify: false },
options,
);
mongoose.set('useCreateIndex', true);

const server = express();

Expand Down
4 changes: 2 additions & 2 deletions api/server/models/Discussion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ class DiscussionClass extends mongoose.Model {
.lean(),
);

await Post.remove({ discussionId: id });
await Post.deleteMany({ discussionId: id });

await this.remove({ _id: id });
await this.deleteOne({ _id: id });

return { teamId: discussion.teamId };
}
Expand Down
8 changes: 4 additions & 4 deletions api/server/models/Invitation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class InvitationClass extends mongoose.Model {
if (team.memberIds.includes(registeredUser._id.toString())) {
throw new Error('This user is already Team Member.');
} else {
await Team.update({ _id: team._id }, { $addToSet: { memberIds: registeredUser._id } });
await Team.updateOne({ _id: team._id }, { $addToSet: { memberIds: registeredUser._id } });

if (registeredUser._id !== team.teamLeaderId && !registeredUser.defaultTeamSlug) {
await User.findByIdAndUpdate(registeredUser._id, {
Expand Down Expand Up @@ -188,7 +188,7 @@ class InvitationClass extends mongoose.Model {
.lean();

if (team && team.memberIds.includes(userId)) {
this.remove({ token }).exec();
this.deleteOne({ token }).exec();
}
}

Expand All @@ -203,14 +203,14 @@ class InvitationClass extends mongoose.Model {
throw new Error('Invitation not found');
}

await this.remove({ token });
await this.deleteOne({ token });

const team = await Team.findById(invitation.teamId)
.select('memberIds slug teamLeaderId')
.lean();

if (team && !team.memberIds.includes(user._id)) {
await Team.update({ _id: team._id }, { $addToSet: { memberIds: user._id } });
await Team.updateOne({ _id: team._id }, { $addToSet: { memberIds: user._id } });

if (user._id !== team.teamLeaderId && !user.defaultTeamSlug) {
await User.findByIdAndUpdate(user._id, { $set: { defaultTeamSlug: team.slug } });
Expand Down
2 changes: 1 addition & 1 deletion api/server/models/Post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class PostClass extends mongoose.Model {

deletePostFiles([post]);

await this.remove({ _id: id });
await this.deleteOne({ _id: id });
}

public static async checkPermission({ userId, discussionId, post = null }) {
Expand Down

0 comments on commit 6bbe205

Please sign in to comment.