Skip to content

Commit

Permalink
Merge pull request #21 from datasci4health/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
matheusmota authored May 15, 2019
2 parents 8d811eb + da2c204 commit 824b753
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 29 deletions.
5 changes: 3 additions & 2 deletions src/adonisjs/app/Controllers/Http/v1/ArtifactController.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ class ArtifactController {
var linkedCase = await Case.find(caseID)

if (caseID != null && linkedCase == null){
return response.json({ message: "User id not found" })
return response.json({ message: "Case id not found" })
}


const artifact = new Artifact()
artifact.fs_path = fsPath + artifactFileName
artifact.relative_path = this.relativePath + artifactFileName
artifact.case_id = linkedCase != null ? linkedCase.id : linkedCase;
artifact.case_id = linkedCase != null ? linkedCase.uuid : linkedCase;
await auth.user.artifacts().save(artifact)

const base_url = Env.getOrFail('APP_URL')
Expand All @@ -71,6 +71,7 @@ class ArtifactController {

})
} catch(e){
console.log('veio')
console.log(e)
return response.status(e.status).json({ message: e.message })
}
Expand Down
8 changes: 4 additions & 4 deletions src/adonisjs/app/Controllers/Http/v1/CaseController.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ const User = use('App/Models/v1/User');
const Case = use('App/Models/v1/Case');
const CaseVersion = use('App/Models/v1/CaseVersion')

const fs = require('fs');

const PLAYER_DIR = "../../player/"
const uuidv4 = require('uuid/v4');

/** * Resourceful controller for interacting with cases */
class CaseController {
Expand Down Expand Up @@ -48,7 +46,7 @@ class CaseController {
let c = await Case.find( params.id )
let versions = await c.versions().fetch()

c.source = versions.first().source
c.source = versions.last().source

return response.json(c)
} catch (e) {
Expand All @@ -60,6 +58,8 @@ class CaseController {
async store({ request, auth, response }) {
try {
let c = new Case()

c.uuid = await uuidv4()
c.name = request.input('name')
c.user_id = auth.user.id

Expand Down
8 changes: 0 additions & 8 deletions src/adonisjs/app/Models/v1/Case.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ class Case extends Model {
versions(){
return this.hasMany('App/Models/v1/CaseVersion')
}

static boot() {
super.boot()

this.addHook('beforeSave', async (caseInstance) => {
caseInstance.uuid = await uuidv4()
})
}
}

module.exports = Case
3 changes: 2 additions & 1 deletion src/adonisjs/database/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ Factory.blueprint('App/Models/v1/User', async (faker, i, data) => {

Factory.blueprint('App/Models/v1/Case', (faker, i, data) => {
return {
name: data.name
name: data.name,
uuid: data.uuid
}
})

Expand Down
39 changes: 25 additions & 14 deletions src/adonisjs/database/seeds/InitialSeeder.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,37 @@
const Factory = use('Factory')

const User = use('App/Models/v1/User');

const Database = use('Database')
const RESOURCE_DIR = "resources/"

const fs = require('fs');
const uuidv4 = require('uuid/v4');

class UserSeeder {
async run() {
let user = new User()
user.username = 'jacinto'
user.email = 'jacinto@example.com'
user.password = 'jacinto'

const c = await Factory.model('App/Models/v1/Case').make({ name: 'case001-development' })
await user.cases().save(c)

const cv = await Factory.model('App/Models/v1/CaseVersion').make({ source: fs.readFileSync(RESOURCE_DIR + 'case.md', 'utf8') })

await c.versions().save(cv)

await Factory.model('App/Models/v1/User').createMany(5)
const trx = await Database.beginTransaction()
try{
let user = new User()
user.username = 'jacinto'
user.email = 'jacinto@example.com'
user.password = 'jacinto'

await user.save(trx)

const c = await Factory.model('App/Models/v1/Case').make({ name: 'case001-development', uuid: await uuidv4() })
await user.cases().save(c, trx)

const cv = await Factory.model('App/Models/v1/CaseVersion').make({ source: fs.readFileSync(RESOURCE_DIR + 'case.md', 'utf8') })

await c.versions().save(cv, trx)

await Factory.model('App/Models/v1/User').createMany(5)

trx.commit()
} catch(e){
console.log('Error on seed process. Transactions rolled back')
trx.rollback()
}
}
}

Expand Down

0 comments on commit 824b753

Please sign in to comment.