Skip to content

Commit

Permalink
Merge pull request #76 from datasci4health/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
lealfp authored Aug 13, 2020
2 parents 756ae23 + 28fcdb6 commit 967da88
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 32 deletions.
62 changes: 32 additions & 30 deletions src/adonisjs/app/Controllers/Http/v1/CaseController.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ class CaseController {
let c = await Case.find( params.id )

if (c != null){
let versions = await CaseVersion.query().where('case_id', '=', params.id ).orderBy('created_at', 'asc').fetch()
let versions = await CaseVersion.query()
.where('case_id', '=', params.id )
.orderBy('created_at', 'asc')
.fetch()

c.source = versions.last().source
c.versions = versions
Expand All @@ -54,34 +57,32 @@ class CaseController {
/** * Create/save a new case.*/
async store({ request, auth, response }) {
try {
console.log(1)
let c = await Case.findBy('title', request.input('title'))

if (c == null) {
c = new Case()
c.id = await uuidv4()
c.title = request.input('title')
c.description = request.input('description')
c.language = request.input('language')
c.domain = request.input('domain')
c.specialty = request.input('specialty')
c.keywords = request.input('keywords')


let cv = new CaseVersion()
cv.id = await uuidv4()
cv.source = request.input('source')

await c.versions().save(cv)
await c.users().attach(auth.user.id, (row) => {
row.role = 0
})

c.versions = await c.versions().fetch()
c.users = await c.users().fetch()
return response.json(c)

} else return response.status(500).json('title already exists')
// let c = await Case.findBy('title', request.input('title'))

// if (c == null) {
let c = new Case()
c.id = await uuidv4()
c.title = request.input('title')
c.description = request.input('description')
c.language = request.input('language')
c.domain = request.input('domain')
c.specialty = request.input('specialty')
c.keywords = request.input('keywords')
c.original_date = request.input('original_date')

let cv = new CaseVersion()
cv.id = await uuidv4()
cv.source = request.input('source')

await c.versions().save(cv)
await c.users().attach(auth.user.id, (row) => {
row.role = 0
})

c.versions = await c.versions().fetch()
c.users = await c.users().fetch()
return response.json(c)
// } else return response.status(500).json('title already exists')

} catch (e) {
console.log(e)
Expand All @@ -101,7 +102,8 @@ class CaseController {
c.domain = request.input('domain')
c.specialty = request.input('specialty')
c.keywords = request.input('keywords')

c.original_date = request.input('original_date')

let cv = new CaseVersion()
cv.source = request.input('source')
cv.id = await uuidv4()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ class CaseSchema extends Schema {
table.uuid('id')
table.primary('id')

table.string('title').notNullable().unique()
table.string('title').notNullable()
table.string('description')
table.string('language', 5)
table.string('domain', 50)
table.string('specialty', 50)
table.string('keywords', 512)
table.string('original_date', 10)

// table.uuid('user_id').references('id').inTable('users').index('user_id');

Expand Down
10 changes: 9 additions & 1 deletion src/adonisjs/database/seeds/InitialSeeder.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const CaseVersion = use('App/Models/v1/CaseVersion');
const Case = use('App/Models/v1/Case');
const User = use('App/Models/v1/User');
const Quest = use('App/Models/v1/Quest');
const Artifact = use('App/Models/v1/Artifact');

const Role = use('App/Models/v1/Role');
const Permission = use('App/Models/v1/Permission');
Expand Down Expand Up @@ -117,7 +118,14 @@ class UserSeeder {
cv.source = fs.readFileSync(RESOURCE_DIR + 'case.md', 'utf8')
cv.id = await uuidv4()


let artifact = new Artifact()
// RESOURCE_DIR + 'hospital-background.png'
// let fs_path = Helpers.publicPath('/resources/artifacts/')
// let case_relative_path = this.relativePath
// fs_path += 'cases/' + case_id + '/'
// case_relative_path += 'cases/' + case_id + '/'

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

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

Expand Down
Binary file added src/adonisjs/resources/hospital-background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 967da88

Please sign in to comment.