Skip to content

Commit

Permalink
fix: 🐛 remove unique constraint from case.title
Browse files Browse the repository at this point in the history
  • Loading branch information
lealfp committed Aug 13, 2020
1 parent 5a2af80 commit 28fcdb6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 36 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: 5 additions & 5 deletions src/adonisjs/database/seeds/InitialSeeder.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ class UserSeeder {
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 + '/'
// 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)

Expand Down

0 comments on commit 28fcdb6

Please sign in to comment.