Skip to content

Commit

Permalink
Merge pull request #121 from harena-lab/development
Browse files Browse the repository at this point in the history
Hotfix: delete caseArtifact link and file
  • Loading branch information
HeitorMatt authored Aug 5, 2021
2 parents b31a687 + 5afdee0 commit 06957dd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
9 changes: 8 additions & 1 deletion src/adonisjs/app/Controllers/Http/v1/ArtifactController.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const Database = use('Database')
const Helpers = use('Helpers')
const Env = use('Env')
const Drive = use('Drive')

const uuid4 = require('uuid/v4')

Expand Down Expand Up @@ -116,8 +117,14 @@ class ArtifactController {
const artifact = await Artifact.findBy('id', params.id)

if (artifact != null) {
await artifact.delete(trx)

await CaseArtifacts
.query()
.where('artifact_id', artifact.id)
.delete()

await artifact.delete(trx)
Drive.delete(Helpers.publicPath(artifact.relative_path))
trx.commit()
return response.json('artifact successfully deleted')
} else {
Expand Down
33 changes: 27 additions & 6 deletions src/adonisjs/app/Controllers/Http/v1/CaseController.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
/** @typedef {import('@adonisjs/framework/src/View')} View */

const Database = use('Database')
const Drive = use('Drive')
const Helpers = use('Helpers')

const User = use('App/Models/v1/User')
const Case = use('App/Models/v1/Case')
Expand All @@ -15,6 +17,8 @@ const Property = use('App/Models/v1/Property')
const CaseProperty = use('App/Models/v1/CaseProperty')
const UsersGroup = use('App/Models/v1/UsersGroup')
const Group = use('App/Models/Group')
const Artifact = use('App/Models/v1/Artifact')
const CaseArtifacts = use('App/Models/CaseArtifact')

const uuidv4 = require('uuid/v4')

Expand Down Expand Up @@ -265,14 +269,31 @@ class CaseController {
.where('table', 'cases')
.where('table_id', c.id)
.delete()
await CaseProperty
.query()
.where('case_id', c.id)
.delete()
// await c.users().detach()
// await c.quests().detach()
await CaseProperty
.query()
.where('case_id', c.id)
.delete()

let _caseArtifacts = Database
.from('case_artifacts')
.where('case_id', c.id)
.select('artifact_id')
await c.artifacts().delete()

// await c.users().detach()
// await c.quests().detach()
let _artifacts = await Database
.from('artifacts')
.whereIn('id', _caseArtifacts)
for (let i = 0; i < _caseArtifacts.length; i++) {
let artifact = await Artifact.find(_caseArtifacts[i].id)
await artifact.delete()
}
let relativeP = ''
for (let i = 0; i < _artifacts.length; i++) {
let path = Helpers.publicPath(_artifacts[i].relative_path)
Drive.delete(path)
}
await c.delete(trx)

trx.commit()
Expand Down

0 comments on commit 06957dd

Please sign in to comment.