mirror of
https://github.com/vkaelin/LeagueStats.git
synced 2026-03-25 12:57:28 +00:00
feat: add ace command to delete specific matches from the db
This commit is contained in:
parent
98fef4785d
commit
df1b0e0ef0
2 changed files with 36 additions and 1 deletions
33
server/app/Commands/DeleteMatch.js
Normal file
33
server/app/Commands/DeleteMatch.js
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
const { Command } = require('@adonisjs/ace')
|
||||||
|
const Database = use('Database')
|
||||||
|
const Match = use('App/Models/Match')
|
||||||
|
|
||||||
|
class DeleteMatch extends Command {
|
||||||
|
static get signature() {
|
||||||
|
return `
|
||||||
|
delete:match
|
||||||
|
{ field : Delete row if entered field is null }
|
||||||
|
`
|
||||||
|
}
|
||||||
|
|
||||||
|
static get description() {
|
||||||
|
return 'Delete matches from db with a condition'
|
||||||
|
}
|
||||||
|
|
||||||
|
async handle(args, options) {
|
||||||
|
console.time('DeleteMatches')
|
||||||
|
const nbMatchesBefore = await Match.count()
|
||||||
|
const matches = await Match.all()
|
||||||
|
for (const match of matches.toJSON()) {
|
||||||
|
await Match.where('_id', match._id).where(args.field, null).delete()
|
||||||
|
}
|
||||||
|
const nbMatchesAfter = await Match.count()
|
||||||
|
Database.close()
|
||||||
|
console.timeEnd('DeleteMatches')
|
||||||
|
this.success(`${this.icon('success')} Delete Matches completed: ${nbMatchesBefore - nbMatchesAfter} matche(s) deleted`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = DeleteMatch
|
||||||
|
|
@ -57,6 +57,8 @@ const aliases = {}
|
||||||
| Here you store ace commands for your package
|
| Here you store ace commands for your package
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
const commands = []
|
const commands = [
|
||||||
|
'App/Commands/DeleteMatch',
|
||||||
|
]
|
||||||
|
|
||||||
module.exports = { providers, aceProviders, aliases, commands }
|
module.exports = { providers, aceProviders, aliases, commands }
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue