From d66fabe387e0902316875b8f1176ebc3c785156c Mon Sep 17 00:00:00 2001 From: HardiReady Date: Sat, 16 Feb 2019 11:47:39 +0100 Subject: [PATCH] Update mongoose method usage o drop deprecated use --- server/config/config.js | 5 +++-- server/routes/campaigns.js | 20 ++++++++++---------- server/routes/decorations.js | 2 +- server/routes/users.js | 2 +- server/test/awardings.spec.js | 2 +- server/test/command.spec.js | 2 +- server/test/decorations.spec.js | 2 +- server/test/ranks.spec.js | 2 +- server/test/squads.spec.js | 4 ++-- server/test/users.spec.js | 2 +- 10 files changed, 22 insertions(+), 21 deletions(-) diff --git a/server/config/config.js b/server/config/config.js index 637fc91..63c0ad3 100644 --- a/server/config/config.js +++ b/server/config/config.js @@ -7,8 +7,9 @@ module.exports = { db: 'cc', mongooseConfig: { useNewUrlParser: true, - useCreateIndex: true - } + useCreateIndex: true, + useFindAndModify: false, + }, }, prod: { diff --git a/server/routes/campaigns.js b/server/routes/campaigns.js index bf72959..0741997 100644 --- a/server/routes/campaigns.js +++ b/server/routes/campaigns.js @@ -104,16 +104,16 @@ campaigns.route('/:id') WarModel.find({campaign: req.params.id}, (err, wars) => { wars.forEach((item) => { // delete linked appearances - PlayerModel.find({warId: item._id}).remove().exec(); - LogKillModel.find({war: item._id}).remove().exec(); - LogVehicleKillModel.find({war: item._id}).remove().exec(); - LogRespawnModel.find({war: item._id}).remove().exec(); - LogReviveModel.find({war: item._id}).remove().exec(); - LogFlagModel.find({war: item._id}).remove().exec(); - LogBudgetModel.find({war: item._id}).remove().exec(); - LogTransportModel.find({war: item._id}).remove().exec(); - LogPointsModel.find({war: item._id}).remove().exec(); - LogPlayerCountModel.find({war: item._id}).remove().exec(); + PlayerModel.find({warId: item._id}).deleteMany(); + LogKillModel.find({war: item._id}).deleteMany(); + LogVehicleKillModel.find({war: item._id}).deleteMany(); + LogRespawnModel.find({war: item._id}).deleteMany(); + LogReviveModel.find({war: item._id}).deleteMany(); + LogFlagModel.find({war: item._id}).deleteMany(); + LogBudgetModel.find({war: item._id}).deleteMany(); + LogTransportModel.find({war: item._id}).deleteMany(); + LogPointsModel.find({war: item._id}).deleteMany(); + LogPlayerCountModel.find({war: item._id}).deleteMany(); // check if logfiles exist and delete from fs const warDir = resourceLocation + item.id; diff --git a/server/routes/decorations.js b/server/routes/decorations.js index 5a90762..89cfabc 100644 --- a/server/routes/decorations.js +++ b/server/routes/decorations.js @@ -170,7 +170,7 @@ decorationRouter.route('/:id') } // deleted all awardings linked to this decoration - AwardingsModel.find({decorationId: id}).remove().exec(); + AwardingsModel.find({decorationId: id}).deleteMany(); // delete graphic fs.unlink(resourceLocation.concat(id).concat('.png'), diff --git a/server/routes/users.js b/server/routes/users.js index 7fc55d1..2e2400a 100644 --- a/server/routes/users.js +++ b/server/routes/users.js @@ -191,7 +191,7 @@ users.route('/:id') } // deleted all awardings linked to this user - AwardingModel.find({userId: req.params.id}).remove().exec(); + AwardingModel.find({userId: req.params.id}).deleteOne(); // check if signature exists and delete compressed and uncompressed file const fileMinified = resourceLocation + req.params.id + '.png'; diff --git a/server/test/awardings.spec.js b/server/test/awardings.spec.js index 10c0206..359c595 100644 --- a/server/test/awardings.spec.js +++ b/server/test/awardings.spec.js @@ -15,7 +15,7 @@ chai.use(chaiHttp); // Our parent block describe('Awardings', () => { beforeEach((done) => { // Before each test we empty the database - AwardingModel.remove({}, (err) => { + AwardingModel.deleteMany({}, (err) => { done(); }); }); diff --git a/server/test/command.spec.js b/server/test/command.spec.js index 2552fc8..84ce8f1 100644 --- a/server/test/command.spec.js +++ b/server/test/command.spec.js @@ -15,7 +15,7 @@ chai.use(chaiHttp); // Our parent block describe('Command', () => { beforeEach((done) => { // Before each test we empty the database - AwardingModel.remove({}, (err) => { + AwardingModel.deleteMany({}, (err) => { done(); }); }); diff --git a/server/test/decorations.spec.js b/server/test/decorations.spec.js index 84e7cc9..728377c 100644 --- a/server/test/decorations.spec.js +++ b/server/test/decorations.spec.js @@ -15,7 +15,7 @@ chai.use(chaiHttp); // Our parent block describe('Decorations', () => { beforeEach((done) => { // Before each test we empty the database - DecorationModel.remove({}, (err) => { + DecorationModel.deleteMany({}, (err) => { done(); }); }); diff --git a/server/test/ranks.spec.js b/server/test/ranks.spec.js index 2518561..b43365c 100644 --- a/server/test/ranks.spec.js +++ b/server/test/ranks.spec.js @@ -15,7 +15,7 @@ chai.use(chaiHttp); // Our parent block describe('Ranks', () => { beforeEach((done) => { // Before each test we empty the database - RankModel.remove({}, (err) => { + RankModel.deleteMany({}, (err) => { done(); }); }); diff --git a/server/test/squads.spec.js b/server/test/squads.spec.js index cf776b8..ebb627e 100644 --- a/server/test/squads.spec.js +++ b/server/test/squads.spec.js @@ -15,7 +15,7 @@ chai.use(chaiHttp); // Our parent block describe('Squads', () => { beforeEach((done) => { // Before each test we empty the database - SquadModel.remove({}, (err) => { + SquadModel.deleteMany({}, (err) => { done(); }); }); @@ -24,7 +24,7 @@ describe('Squads', () => { */ describe('/GET squads', () => { it('it should GET all the squads', (done) => { - chai.request(server) + chai.deleteMany(server) .get(urls.squads) .end((err, res) => { res.should.have.status(codes.success); diff --git a/server/test/users.spec.js b/server/test/users.spec.js index 432b8a6..9b8b158 100644 --- a/server/test/users.spec.js +++ b/server/test/users.spec.js @@ -15,7 +15,7 @@ chai.use(chaiHttp); // Our parent block describe('Users', () => { beforeEach((done) => { // Before each test we empty the database - UserModel.remove({}, (err) => { + UserModel.deleteMany({}, (err) => { done(); }); });