Skip to content

Commit

Permalink
Merge pull request #122 from harena-lab/development
Browse files Browse the repository at this point in the history
fix (artifacts): delecting artifacts of a deleted case
  • Loading branch information
santanche authored Nov 6, 2021
2 parents 06957dd + 4682933 commit 4567dc8
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/adonisjs/app/Controllers/Http/v1/CaseController.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,26 +274,22 @@ class CaseController {
.where('case_id', c.id)
.delete()

let _caseArtifacts = Database
let _caseArtifacts = await 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)
for (let i in _caseArtifacts) {
let artifact = await Artifact.find(_caseArtifacts[i].artifact_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)
}

console.log('================= deleting the directory')
let dir_delete = Helpers.publicPath('/resources/artifacts/cases/') + c.id
console.log(dir_delete)
Drive.delete(dir_delete)

await c.delete(trx)

trx.commit()
Expand Down

0 comments on commit 4567dc8

Please sign in to comment.