Skip to content
This repository has been archived by the owner on Oct 14, 2020. It is now read-only.

Commit

Permalink
Minor fixups
Browse files Browse the repository at this point in the history
  * assert we use non-deprecated moment.subtract(num, period)
  * close mongo client and not the connection
  • Loading branch information
kkuehlz committed May 4, 2020
1 parent a8c9a83 commit 4883e66
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions bin/remove-feedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ const args = require('yargs')
.argv

const main = async (args) => {
MongoClient.connect(mongoURL, (err, connection) => {
const collection = connection.collection(FEEDBACK_COLLECTION);
MongoClient.connect(mongoURL, (err, client) => {
const db = client.db()

const collection = db.collection(FEEDBACK_COLLECTION);
if (args.id) {
collection.deleteOne({ id : args.id }, (err, result) => {
assert.equal(err, null)
Expand All @@ -25,25 +27,26 @@ const main = async (args) => {
} else {
console.log(`Feedback with id ${args.id} removed`)
}
connection.close()
client.close()
})
} else if (args.interval) {
let [num, period] = args.interval.split(' ')
num = parseInt(num)
assert(typeof(period) === 'string')
const targetYMD = moment().subtract(num, period).format('YYYY-MM-DD')
console.log(`This will remove all feedback before ${targetYMD}. Run again with -f to accept`)
if (targetYMD && args.f) {
console.log(`removing all feedback before ${targetYMD}`)
collection.deleteMany({ ymd: { $lt: targetYMD }}, (err, result) => {
assert.equal(err, null)
console.log(`${result.result.n} feedback records removed`)
connection.close()
client.close()
})
} else {
connection.close()
client.close()
}
} else {
connection.close()
client.close()
}
})
}
Expand Down

0 comments on commit 4883e66

Please sign in to comment.